[red-knot] Litate tests: minor follow-up (#15987)
## Summary - Minor wording update - Code improvement (thanks Alex) - Removed all unnecessary filenames throughout our Markdown tests (two new ones were added in the meantime) - Minor rewording of the statically-known-branches introduction
This commit is contained in:
@@ -393,8 +393,6 @@ reveal_type(D().x) # revealed: Unknown | Literal[1]
|
||||
|
||||
If `staticmethod` is something else, that should not influence the behavior:
|
||||
|
||||
`other.py`:
|
||||
|
||||
```py
|
||||
def staticmethod(f):
|
||||
return f
|
||||
@@ -409,8 +407,6 @@ reveal_type(C().x) # revealed: Unknown | Literal[1]
|
||||
|
||||
And if `staticmethod` is fully qualified, that should also be recognized:
|
||||
|
||||
`fully_qualified.py`:
|
||||
|
||||
```py
|
||||
import builtins
|
||||
|
||||
|
||||
@@ -7,43 +7,36 @@ branches whose conditions we can statically determine to be always true or alway
|
||||
useful for `sys.version_info` branches, which can make new features available based on the Python
|
||||
version:
|
||||
|
||||
`module1.py`:
|
||||
If we can statically determine that the condition is always true, then we can also understand that
|
||||
`SomeFeature` is always bound, without raising any errors:
|
||||
|
||||
```py
|
||||
import sys
|
||||
|
||||
if sys.version_info >= (3, 9):
|
||||
SomeFeature: str = "available"
|
||||
```
|
||||
class C:
|
||||
if sys.version_info >= (3, 9):
|
||||
SomeFeature: str = "available"
|
||||
|
||||
If we can statically determine that the condition is always true, then we can also understand that
|
||||
`SomeFeature` is always bound, without raising any errors:
|
||||
|
||||
`test1.py`:
|
||||
|
||||
```py
|
||||
from module1 import SomeFeature
|
||||
|
||||
# SomeFeature is unconditionally available here, because we are on Python 3.9 or newer:
|
||||
reveal_type(SomeFeature) # revealed: str
|
||||
# C.SomeFeature is unconditionally available here, because we are on Python 3.9 or newer:
|
||||
reveal_type(C.SomeFeature) # revealed: str
|
||||
```
|
||||
|
||||
Another scenario where this is useful is for `typing.TYPE_CHECKING` branches, which are often used
|
||||
for conditional imports:
|
||||
|
||||
`module2.py`:
|
||||
`module.py`:
|
||||
|
||||
```py
|
||||
class SomeType: ...
|
||||
```
|
||||
|
||||
`test2.py`:
|
||||
`main.py`:
|
||||
|
||||
```py
|
||||
import typing
|
||||
|
||||
if typing.TYPE_CHECKING:
|
||||
from module2 import SomeType
|
||||
from module import SomeType
|
||||
|
||||
# `SomeType` is unconditionally available here for type checkers:
|
||||
def f(s: SomeType) -> None: ...
|
||||
|
||||
Reference in New Issue
Block a user