ruff
f0214e0c - [ty] Limit wildcard exports using literal `__all__` (#28972)

Commit
18 days ago
[ty] Limit wildcard exports using literal `__all__` (#28972) ## Summary When a module imports a large namespace and then defines a small `__all__`, we currently include every imported name when another module uses a wildcard import. Packages with many such modules can create hundreds of thousands of unnecessary definitions and reachability constraints. This PR instead recognizes an unchanged literal `__all__` before semantic indexing and limits the possible exports to its names. Other uses of `__all__`, including mutations and later wildcard imports, fall back to the existing analysis. So this fixes narrow (but non-contrived) cases. For the `pulumi-cloudflare` reproduction in [astral-sh/ty#4606](https://github.com/astral-sh/ty/issues/4606), peak memory goes from 5,649-6,344 MiB to 453-459 MiB. This also changes some diagnostics by avoiding cycles during import resolution. Previously, determining the contents of `__all__` could require type inference that depended on imports we were still resolving, leaving some types as `Divergent`. Reading the literal directly breaks those cycles, so we resolve more types successfully. This removes spurious warnings and enables checks that were previously skipped because the relevant types were unresolved.
Author
Parents
Loading