mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 10:48:32 +00:00
[ty] __file__ is always a string inside a Python module (#18071)
## Summary Understand that `__file__` is always set and a `str` when looked up as an implicit global from a Python file we are type checking. ## Test Plan mdtests
This commit is contained in:
parent
142c1bc760
commit
f8890b70c3
2 changed files with 13 additions and 2 deletions
|
@ -8,7 +8,8 @@ is unbound.
|
|||
|
||||
```py
|
||||
reveal_type(__name__) # revealed: str
|
||||
reveal_type(__file__) # revealed: str | None
|
||||
# Typeshed says this is str | None, but for a pure-Python on-disk module its always str
|
||||
reveal_type(__file__) # revealed: str
|
||||
reveal_type(__loader__) # revealed: LoaderProtocol | None
|
||||
reveal_type(__package__) # revealed: str | None
|
||||
reveal_type(__doc__) # revealed: str | None
|
||||
|
@ -52,6 +53,10 @@ import typing
|
|||
reveal_type(typing.__name__) # revealed: str
|
||||
reveal_type(typing.__init__) # revealed: bound method ModuleType.__init__(name: str, doc: str | None = ellipsis) -> None
|
||||
|
||||
# For a stub module, we don't know that `__file__` is a string (at runtime it may be entirely
|
||||
# unset, but we follow typeshed here):
|
||||
reveal_type(typing.__file__) # revealed: str | None
|
||||
|
||||
# These come from `builtins.object`, not `types.ModuleType`:
|
||||
reveal_type(typing.__eq__) # revealed: bound method ModuleType.__eq__(value: object, /) -> bool
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue