mirror of https://github.com/astral-sh/ruff
Update more tests
This commit is contained in:
parent
99ebf3746c
commit
9452f2c7f6
|
|
@ -784,7 +784,7 @@ class A: ...
|
|||
from subexporter import *
|
||||
|
||||
# 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")
|
||||
|
||||
|
|
|
|||
|
|
@ -40,10 +40,10 @@ def __getattr__(name: str) -> int:
|
|||
import mixed_module
|
||||
|
||||
# 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
|
||||
reveal_type(mixed_module.dynamic_attr) # revealed: str
|
||||
reveal_type(mixed_module.dynamic_attr) # revealed: int
|
||||
```
|
||||
|
||||
`mixed_module.py`:
|
||||
|
|
@ -51,8 +51,8 @@ reveal_type(mixed_module.dynamic_attr) # revealed: str
|
|||
```py
|
||||
explicit_attr = "explicit"
|
||||
|
||||
def __getattr__(name: str) -> str:
|
||||
return "dynamic"
|
||||
def __getattr__(name: str) -> int:
|
||||
return 1
|
||||
```
|
||||
|
||||
## Precedence: submodules vs `__getattr__`
|
||||
|
|
|
|||
|
|
@ -91,19 +91,23 @@ If there's a namespace package with the same name as a module, the module takes
|
|||
`foo.py`:
|
||||
|
||||
```py
|
||||
x = "module"
|
||||
class FromModule: ...
|
||||
|
||||
x = FromModule
|
||||
```
|
||||
|
||||
`foo/bar.py`:
|
||||
|
||||
```py
|
||||
x = "namespace"
|
||||
class FromNamespace: ...
|
||||
|
||||
x = FromNamespace
|
||||
```
|
||||
|
||||
```py
|
||||
from foo import x
|
||||
|
||||
reveal_type(x) # revealed: Unknown | Literal["module"]
|
||||
reveal_type(x) # revealed: <class 'FromModule'>
|
||||
|
||||
import foo.bar # error: [unresolved-import]
|
||||
```
|
||||
|
|
|
|||
|
|
@ -144,8 +144,8 @@ X = (Y := 3) + 4
|
|||
```py
|
||||
from exporter import *
|
||||
|
||||
reveal_type(X) # revealed: Unknown | Literal[7]
|
||||
reveal_type(Y) # revealed: Unknown | Literal[3]
|
||||
reveal_type(X) # revealed: int
|
||||
reveal_type(Y) # revealed: int
|
||||
```
|
||||
|
||||
### Global-scope symbols defined in many other ways
|
||||
|
|
@ -781,9 +781,9 @@ else:
|
|||
from exporter import *
|
||||
|
||||
# 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
|
||||
|
|
@ -804,7 +804,7 @@ if coinflip():
|
|||
from exporter import *
|
||||
|
||||
# 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
|
||||
|
|
|
|||
|
|
@ -167,11 +167,11 @@ if c.x is not None:
|
|||
|
||||
if c.x is not None:
|
||||
def _():
|
||||
reveal_type(c.x) # revealed: Unknown | int | None
|
||||
reveal_type(c.x) # revealed: int | None
|
||||
|
||||
def _():
|
||||
if c.x is not None:
|
||||
reveal_type(c.x) # revealed: (Unknown & ~None) | int
|
||||
reveal_type(c.x) # revealed: int
|
||||
```
|
||||
|
||||
## Subscript narrowing
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ class B:
|
|||
reveal_type(a.x) # revealed: Literal["a"]
|
||||
|
||||
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"]
|
||||
|
||||
|
|
@ -96,7 +96,7 @@ class C:
|
|||
reveal_type(a.x) # revealed: str | None
|
||||
|
||||
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
|
||||
|
||||
|
|
@ -109,7 +109,7 @@ class D:
|
|||
reveal_type(a.x) # revealed: Literal["a"]
|
||||
|
||||
def h():
|
||||
reveal_type(a.x) # revealed: Unknown | str | None
|
||||
reveal_type(a.x) # revealed: str | None
|
||||
|
||||
# TODO: should be `str | None`
|
||||
[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
|
||||
|
||||
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:
|
||||
reveal_type(l[0]) # revealed: str
|
||||
|
|
@ -206,7 +206,7 @@ def f(x: str | None):
|
|||
reveal_type(g) # revealed: str
|
||||
|
||||
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:
|
||||
reveal_type(l[0]) # revealed: str
|
||||
|
|
@ -382,12 +382,12 @@ def f():
|
|||
if a.x is not None:
|
||||
def _():
|
||||
# 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:
|
||||
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:
|
||||
def _():
|
||||
|
|
@ -473,11 +473,11 @@ def f():
|
|||
if a.x is not None:
|
||||
def _():
|
||||
if a.x != 1:
|
||||
reveal_type(a.x) # revealed: (Unknown & ~Literal[1]) | str | None
|
||||
reveal_type(a.x) # revealed: str | None
|
||||
|
||||
class D:
|
||||
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:
|
||||
def _():
|
||||
|
|
|
|||
|
|
@ -29,8 +29,8 @@ if flag():
|
|||
chr: int = 1
|
||||
|
||||
def _():
|
||||
# TODO: Should ideally be `Unknown | Literal[1] | (def abs(x: SupportsAbs[_T], /) -> _T)`
|
||||
reveal_type(abs) # revealed: Unknown | Literal[1]
|
||||
# TODO: Should ideally be `Literal[1] | (def abs(x: SupportsAbs[_T], /) -> _T)`
|
||||
reveal_type(abs) # revealed: int
|
||||
# TODO: Should ideally be `int | (def chr(i: SupportsIndex, /) -> str)`
|
||||
reveal_type(chr) # revealed: int
|
||||
```
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ Function definitions are evaluated lazily.
|
|||
x = 1
|
||||
|
||||
def f():
|
||||
reveal_type(x) # revealed: Unknown | Literal[1, 2]
|
||||
reveal_type(x) # revealed: int
|
||||
|
||||
x = 2
|
||||
```
|
||||
|
|
@ -283,7 +283,7 @@ x = 1
|
|||
|
||||
def _():
|
||||
class C:
|
||||
# revealed: Unknown | Literal[1]
|
||||
# revealed: int
|
||||
[reveal_type(x) for _ in [1]]
|
||||
x = 2
|
||||
```
|
||||
|
|
@ -389,7 +389,7 @@ x = int
|
|||
class C:
|
||||
var: ClassVar[x]
|
||||
|
||||
reveal_type(C.var) # revealed: Unknown | int | str
|
||||
reveal_type(C.var) # revealed: int | str
|
||||
|
||||
x = str
|
||||
```
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ A name reference to a never-defined symbol in a function is implicitly a global
|
|||
x = 1
|
||||
|
||||
def f():
|
||||
reveal_type(x) # revealed: Unknown | Literal[1]
|
||||
reveal_type(x) # revealed: int
|
||||
```
|
||||
|
||||
## Explicit global in function
|
||||
|
|
@ -18,7 +18,7 @@ x = 1
|
|||
|
||||
def f():
|
||||
global x
|
||||
reveal_type(x) # revealed: Unknown | Literal[1]
|
||||
reveal_type(x) # revealed: int
|
||||
```
|
||||
|
||||
## Unassignable type in function
|
||||
|
|
@ -201,7 +201,7 @@ x = 42
|
|||
|
||||
def f():
|
||||
global x
|
||||
reveal_type(x) # revealed: Unknown | Literal[42]
|
||||
reveal_type(x) # revealed: int
|
||||
x = "56"
|
||||
reveal_type(x) # revealed: Literal["56"]
|
||||
```
|
||||
|
|
|
|||
|
|
@ -73,10 +73,10 @@ __spec__ = 42 # error: [invalid-assignment] "Object of type `Literal[42]` is no
|
|||
```py
|
||||
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.__doc__) # revealed: Unknown
|
||||
reveal_type(module.__spec__) # revealed: Unknown | ModuleSpec | None
|
||||
reveal_type(module.__spec__) # revealed: ModuleSpec | None
|
||||
# error: [unresolved-attribute]
|
||||
reveal_type(module.__warningregistry__) # revealed: Unknown
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ class C:
|
|||
x = 2
|
||||
|
||||
# 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]
|
||||
```
|
||||
|
||||
|
|
@ -37,7 +37,7 @@ class C:
|
|||
# Possibly unbound variables in enclosing scopes are considered bound.
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,2 +1 @@
|
|||
spark # too many iterations (in `exported_names` query)
|
||||
steam.py # hangs (single threaded)
|
||||
|
|
|
|||
Loading…
Reference in New Issue