Update more tests

This commit is contained in:
David Peter 2025-09-30 14:32:51 +02:00
parent 99ebf3746c
commit 9452f2c7f6
12 changed files with 41 additions and 38 deletions

View File

@ -784,7 +784,7 @@ class A: ...
from subexporter import * from subexporter import *
# TODO: Should we avoid including `Unknown` for this case? # TODO: Should we avoid including `Unknown` for this case?
reveal_type(__all__) # revealed: Unknown | list[Unknown | str] reveal_type(__all__) # revealed: list[Unknown | str]
__all__.append("B") __all__.append("B")

View File

@ -40,10 +40,10 @@ def __getattr__(name: str) -> int:
import mixed_module import mixed_module
# Explicit attribute should take precedence # Explicit attribute should take precedence
reveal_type(mixed_module.explicit_attr) # revealed: Unknown | Literal["explicit"] reveal_type(mixed_module.explicit_attr) # revealed: str
# `__getattr__` should handle unknown attributes # `__getattr__` should handle unknown attributes
reveal_type(mixed_module.dynamic_attr) # revealed: str reveal_type(mixed_module.dynamic_attr) # revealed: int
``` ```
`mixed_module.py`: `mixed_module.py`:
@ -51,8 +51,8 @@ reveal_type(mixed_module.dynamic_attr) # revealed: str
```py ```py
explicit_attr = "explicit" explicit_attr = "explicit"
def __getattr__(name: str) -> str: def __getattr__(name: str) -> int:
return "dynamic" return 1
``` ```
## Precedence: submodules vs `__getattr__` ## Precedence: submodules vs `__getattr__`

View File

@ -91,19 +91,23 @@ If there's a namespace package with the same name as a module, the module takes
`foo.py`: `foo.py`:
```py ```py
x = "module" class FromModule: ...
x = FromModule
``` ```
`foo/bar.py`: `foo/bar.py`:
```py ```py
x = "namespace" class FromNamespace: ...
x = FromNamespace
``` ```
```py ```py
from foo import x from foo import x
reveal_type(x) # revealed: Unknown | Literal["module"] reveal_type(x) # revealed: <class 'FromModule'>
import foo.bar # error: [unresolved-import] import foo.bar # error: [unresolved-import]
``` ```

View File

@ -144,8 +144,8 @@ X = (Y := 3) + 4
```py ```py
from exporter import * from exporter import *
reveal_type(X) # revealed: Unknown | Literal[7] reveal_type(X) # revealed: int
reveal_type(Y) # revealed: Unknown | Literal[3] reveal_type(Y) # revealed: int
``` ```
### Global-scope symbols defined in many other ways ### Global-scope symbols defined in many other ways
@ -781,9 +781,9 @@ else:
from exporter import * from exporter import *
# error: [possibly-unresolved-reference] # error: [possibly-unresolved-reference]
reveal_type(A) # revealed: Unknown | Literal[1] reveal_type(A) # revealed: int
reveal_type(B) # revealed: Unknown | Literal[2, 3] reveal_type(B) # revealed: int
``` ```
### Reachability constraints in the importing module ### Reachability constraints in the importing module
@ -804,7 +804,7 @@ if coinflip():
from exporter import * from exporter import *
# error: [possibly-unresolved-reference] # error: [possibly-unresolved-reference]
reveal_type(A) # revealed: Unknown | Literal[1] reveal_type(A) # revealed: int
``` ```
### Reachability constraints in the exporting module *and* the importing module ### Reachability constraints in the exporting module *and* the importing module

View File

@ -167,11 +167,11 @@ if c.x is not None:
if c.x is not None: if c.x is not None:
def _(): def _():
reveal_type(c.x) # revealed: Unknown | int | None reveal_type(c.x) # revealed: int | None
def _(): def _():
if c.x is not None: if c.x is not None:
reveal_type(c.x) # revealed: (Unknown & ~None) | int reveal_type(c.x) # revealed: int
``` ```
## Subscript narrowing ## Subscript narrowing

View File

@ -86,7 +86,7 @@ class B:
reveal_type(a.x) # revealed: Literal["a"] reveal_type(a.x) # revealed: Literal["a"]
def f(): def f():
reveal_type(a.x) # revealed: Unknown | str | None reveal_type(a.x) # revealed: str | None
[reveal_type(a.x) for _ in range(1)] # revealed: Literal["a"] [reveal_type(a.x) for _ in range(1)] # revealed: Literal["a"]
@ -96,7 +96,7 @@ class C:
reveal_type(a.x) # revealed: str | None reveal_type(a.x) # revealed: str | None
def g(): def g():
reveal_type(a.x) # revealed: Unknown | str | None reveal_type(a.x) # revealed: str | None
[reveal_type(a.x) for _ in range(1)] # revealed: str | None [reveal_type(a.x) for _ in range(1)] # revealed: str | None
@ -109,7 +109,7 @@ class D:
reveal_type(a.x) # revealed: Literal["a"] reveal_type(a.x) # revealed: Literal["a"]
def h(): def h():
reveal_type(a.x) # revealed: Unknown | str | None reveal_type(a.x) # revealed: str | None
# TODO: should be `str | None` # TODO: should be `str | None`
[reveal_type(a.x) for _ in range(1)] # revealed: Literal["a"] [reveal_type(a.x) for _ in range(1)] # revealed: Literal["a"]
@ -190,7 +190,7 @@ def f(x: str | None):
reveal_type(g) # revealed: str reveal_type(g) # revealed: str
if a.x is not None: if a.x is not None:
reveal_type(a.x) # revealed: (Unknown & ~None) | str reveal_type(a.x) # revealed: str
if l[0] is not None: if l[0] is not None:
reveal_type(l[0]) # revealed: str reveal_type(l[0]) # revealed: str
@ -206,7 +206,7 @@ def f(x: str | None):
reveal_type(g) # revealed: str reveal_type(g) # revealed: str
if a.x is not None: if a.x is not None:
reveal_type(a.x) # revealed: (Unknown & ~None) | str reveal_type(a.x) # revealed: str
if l[0] is not None: if l[0] is not None:
reveal_type(l[0]) # revealed: str reveal_type(l[0]) # revealed: str
@ -382,12 +382,12 @@ def f():
if a.x is not None: if a.x is not None:
def _(): def _():
# Lazy nested scope narrowing is not performed on attributes/subscripts because it's difficult to track their changes. # Lazy nested scope narrowing is not performed on attributes/subscripts because it's difficult to track their changes.
reveal_type(a.x) # revealed: Unknown | str | None reveal_type(a.x) # revealed: str | None
class D: class D:
reveal_type(a.x) # revealed: (Unknown & ~None) | str reveal_type(a.x) # revealed: str
[reveal_type(a.x) for _ in range(1)] # revealed: (Unknown & ~None) | str [reveal_type(a.x) for _ in range(1)] # revealed: str
if l[0] is not None: if l[0] is not None:
def _(): def _():
@ -473,11 +473,11 @@ def f():
if a.x is not None: if a.x is not None:
def _(): def _():
if a.x != 1: if a.x != 1:
reveal_type(a.x) # revealed: (Unknown & ~Literal[1]) | str | None reveal_type(a.x) # revealed: str | None
class D: class D:
if a.x != 1: if a.x != 1:
reveal_type(a.x) # revealed: (Unknown & ~Literal[1] & ~None) | str reveal_type(a.x) # revealed: str
if l[0] is not None: if l[0] is not None:
def _(): def _():

View File

@ -29,8 +29,8 @@ if flag():
chr: int = 1 chr: int = 1
def _(): def _():
# TODO: Should ideally be `Unknown | Literal[1] | (def abs(x: SupportsAbs[_T], /) -> _T)` # TODO: Should ideally be `Literal[1] | (def abs(x: SupportsAbs[_T], /) -> _T)`
reveal_type(abs) # revealed: Unknown | Literal[1] reveal_type(abs) # revealed: int
# TODO: Should ideally be `int | (def chr(i: SupportsIndex, /) -> str)` # TODO: Should ideally be `int | (def chr(i: SupportsIndex, /) -> str)`
reveal_type(chr) # revealed: int reveal_type(chr) # revealed: int
``` ```

View File

@ -12,7 +12,7 @@ Function definitions are evaluated lazily.
x = 1 x = 1
def f(): def f():
reveal_type(x) # revealed: Unknown | Literal[1, 2] reveal_type(x) # revealed: int
x = 2 x = 2
``` ```
@ -283,7 +283,7 @@ x = 1
def _(): def _():
class C: class C:
# revealed: Unknown | Literal[1] # revealed: int
[reveal_type(x) for _ in [1]] [reveal_type(x) for _ in [1]]
x = 2 x = 2
``` ```
@ -389,7 +389,7 @@ x = int
class C: class C:
var: ClassVar[x] var: ClassVar[x]
reveal_type(C.var) # revealed: Unknown | int | str reveal_type(C.var) # revealed: int | str
x = str x = str
``` ```

View File

@ -8,7 +8,7 @@ A name reference to a never-defined symbol in a function is implicitly a global
x = 1 x = 1
def f(): def f():
reveal_type(x) # revealed: Unknown | Literal[1] reveal_type(x) # revealed: int
``` ```
## Explicit global in function ## Explicit global in function
@ -18,7 +18,7 @@ x = 1
def f(): def f():
global x global x
reveal_type(x) # revealed: Unknown | Literal[1] reveal_type(x) # revealed: int
``` ```
## Unassignable type in function ## Unassignable type in function
@ -201,7 +201,7 @@ x = 42
def f(): def f():
global x global x
reveal_type(x) # revealed: Unknown | Literal[42] reveal_type(x) # revealed: int
x = "56" x = "56"
reveal_type(x) # revealed: Literal["56"] reveal_type(x) # revealed: Literal["56"]
``` ```

View File

@ -73,10 +73,10 @@ __spec__ = 42 # error: [invalid-assignment] "Object of type `Literal[42]` is no
```py ```py
import module import module
reveal_type(module.__file__) # revealed: Unknown | None reveal_type(module.__file__) # revealed: None
reveal_type(module.__path__) # revealed: list[str] reveal_type(module.__path__) # revealed: list[str]
reveal_type(module.__doc__) # revealed: Unknown reveal_type(module.__doc__) # revealed: Unknown
reveal_type(module.__spec__) # revealed: Unknown | ModuleSpec | None reveal_type(module.__spec__) # revealed: ModuleSpec | None
# error: [unresolved-attribute] # error: [unresolved-attribute]
reveal_type(module.__warningregistry__) # revealed: Unknown reveal_type(module.__warningregistry__) # revealed: Unknown

View File

@ -17,7 +17,7 @@ class C:
x = 2 x = 2
# error: [possibly-missing-attribute] "Attribute `x` on type `<class 'C'>` may be missing" # error: [possibly-missing-attribute] "Attribute `x` on type `<class 'C'>` may be missing"
reveal_type(C.x) # revealed: Unknown | Literal[2] reveal_type(C.x) # revealed: Unknown | int
reveal_type(C.y) # revealed: Unknown | Literal[1] reveal_type(C.y) # revealed: Unknown | Literal[1]
``` ```
@ -37,7 +37,7 @@ class C:
# Possibly unbound variables in enclosing scopes are considered bound. # Possibly unbound variables in enclosing scopes are considered bound.
y = x y = x
reveal_type(C.y) # revealed: Unknown | Literal[1, "abc"] reveal_type(C.y) # revealed: Unknown | Literal[1] | str
``` ```
## Possibly unbound in class scope with multiple declarations ## Possibly unbound in class scope with multiple declarations

View File

@ -1,2 +1 @@
spark # too many iterations (in `exported_names` query) spark # too many iterations (in `exported_names` query)
steam.py # hangs (single threaded)