mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 18:28:24 +00:00
[ty] Support extending __all__
from an imported module even when the module is not an ExprName
node (#17947)
This commit is contained in:
parent
9b694ada82
commit
f51f1f7153
5 changed files with 147 additions and 31 deletions
|
@ -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`:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue