diff --git a/crates/ty_python_semantic/resources/mdtest/import/dunder_all.md b/crates/ty_python_semantic/resources/mdtest/import/dunder_all.md index 1fcdefb2dd..d80301f851 100644 --- a/crates/ty_python_semantic/resources/mdtest/import/dunder_all.md +++ b/crates/ty_python_semantic/resources/mdtest/import/dunder_all.md @@ -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") diff --git a/crates/ty_python_semantic/resources/mdtest/import/module_getattr.md b/crates/ty_python_semantic/resources/mdtest/import/module_getattr.md index 8e947ab655..7d1665ef96 100644 --- a/crates/ty_python_semantic/resources/mdtest/import/module_getattr.md +++ b/crates/ty_python_semantic/resources/mdtest/import/module_getattr.md @@ -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__` diff --git a/crates/ty_python_semantic/resources/mdtest/import/namespace.md b/crates/ty_python_semantic/resources/mdtest/import/namespace.md index 3b5f63e981..af7d1ab036 100644 --- a/crates/ty_python_semantic/resources/mdtest/import/namespace.md +++ b/crates/ty_python_semantic/resources/mdtest/import/namespace.md @@ -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: import foo.bar # error: [unresolved-import] ``` diff --git a/crates/ty_python_semantic/resources/mdtest/import/star.md b/crates/ty_python_semantic/resources/mdtest/import/star.md index c66012b103..ae7dc6bb98 100644 --- a/crates/ty_python_semantic/resources/mdtest/import/star.md +++ b/crates/ty_python_semantic/resources/mdtest/import/star.md @@ -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 diff --git a/crates/ty_python_semantic/resources/mdtest/narrow/complex_target.md b/crates/ty_python_semantic/resources/mdtest/narrow/complex_target.md index 5a61c9e8d2..479238d617 100644 --- a/crates/ty_python_semantic/resources/mdtest/narrow/complex_target.md +++ b/crates/ty_python_semantic/resources/mdtest/narrow/complex_target.md @@ -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 diff --git a/crates/ty_python_semantic/resources/mdtest/narrow/conditionals/nested.md b/crates/ty_python_semantic/resources/mdtest/narrow/conditionals/nested.md index dd10ff9585..f27b3deb08 100644 --- a/crates/ty_python_semantic/resources/mdtest/narrow/conditionals/nested.md +++ b/crates/ty_python_semantic/resources/mdtest/narrow/conditionals/nested.md @@ -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 _(): diff --git a/crates/ty_python_semantic/resources/mdtest/scopes/builtin.md b/crates/ty_python_semantic/resources/mdtest/scopes/builtin.md index ae684a22d9..b1dd1fbef6 100644 --- a/crates/ty_python_semantic/resources/mdtest/scopes/builtin.md +++ b/crates/ty_python_semantic/resources/mdtest/scopes/builtin.md @@ -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 ``` diff --git a/crates/ty_python_semantic/resources/mdtest/scopes/eager.md b/crates/ty_python_semantic/resources/mdtest/scopes/eager.md index 286f2eb261..d8fdd5e0c9 100644 --- a/crates/ty_python_semantic/resources/mdtest/scopes/eager.md +++ b/crates/ty_python_semantic/resources/mdtest/scopes/eager.md @@ -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 ``` diff --git a/crates/ty_python_semantic/resources/mdtest/scopes/global.md b/crates/ty_python_semantic/resources/mdtest/scopes/global.md index e7156e85de..21479dc5f2 100644 --- a/crates/ty_python_semantic/resources/mdtest/scopes/global.md +++ b/crates/ty_python_semantic/resources/mdtest/scopes/global.md @@ -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"] ``` diff --git a/crates/ty_python_semantic/resources/mdtest/scopes/moduletype_attrs.md b/crates/ty_python_semantic/resources/mdtest/scopes/moduletype_attrs.md index 7c6c3e6d9e..16240e81d9 100644 --- a/crates/ty_python_semantic/resources/mdtest/scopes/moduletype_attrs.md +++ b/crates/ty_python_semantic/resources/mdtest/scopes/moduletype_attrs.md @@ -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 diff --git a/crates/ty_python_semantic/resources/mdtest/scopes/unbound.md b/crates/ty_python_semantic/resources/mdtest/scopes/unbound.md index 43c8f5f564..71b483cf87 100644 --- a/crates/ty_python_semantic/resources/mdtest/scopes/unbound.md +++ b/crates/ty_python_semantic/resources/mdtest/scopes/unbound.md @@ -17,7 +17,7 @@ class C: x = 2 # error: [possibly-missing-attribute] "Attribute `x` on type `` 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 diff --git a/crates/ty_python_semantic/resources/primer/bad.txt b/crates/ty_python_semantic/resources/primer/bad.txt index bfff92bd22..59fa3b5d6e 100644 --- a/crates/ty_python_semantic/resources/primer/bad.txt +++ b/crates/ty_python_semantic/resources/primer/bad.txt @@ -1,2 +1 @@ spark # too many iterations (in `exported_names` query) -steam.py # hangs (single threaded)