[ty] Support extending __all__ from an imported module even when the module is not an ExprName node (#17947)

This commit is contained in:
Alex Waygood 2025-05-08 23:54:19 +01:00 committed by GitHub
parent 9b694ada82
commit f51f1f7153
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 147 additions and 31 deletions

View file

@ -251,6 +251,53 @@ from ty_extensions import dunder_all_names
reveal_type(dunder_all_names(exporter))
```
### Augmenting list with a list or submodule `__all__` (2)
The same again, but the submodule is an attribute expression rather than a name expression:
`exporter/__init__.py`:
```py
```
`exporter/sub.py`:
```py
__all__ = ["foo"]
foo = 42
```
`exporter/sub2.py`:
```py
__all__ = ["bar"]
bar = 56
```
`module.py`:
```py
import exporter.sub
import exporter.sub2
__all__ = []
if True:
__all__.extend(exporter.sub.__all__)
__all__ += exporter.sub2.__all__
```
`main.py`:
```py
import module
from ty_extensions import dunder_all_names
reveal_type(dunder_all_names(module)) # revealed: tuple[Literal["bar"], Literal["foo"]]
```
### Extending with a list or submodule `__all__`
`subexporter.py`: