Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2476,7 +2476,10 @@ def analyze_unbound_tvar_impl(
assert not is_unpacked or not is_typealias_param, "Mutually exclusive conditions"
sym = self.lookup_qualified(t.name, t)
if sym and isinstance(sym.node, PlaceholderNode):
self.record_incomplete_ref()
if self.final_iteration:
self.cannot_resolve_name(t.name, "name", t)
else:
self.record_incomplete_ref()
if not is_unpacked and sym and isinstance(sym.node, ParamSpecExpr):
if sym.fullname and not self.tvar_scope.allow_binding(sym.fullname):
# It's bound by our type variable scope
Expand Down
17 changes: 17 additions & 0 deletions test-data/unit/check-newsemanal.test
Original file line number Diff line number Diff line change
Expand Up @@ -3316,3 +3316,20 @@ class D: ...

x: A
reveal_type(x) # N: Revealed type is "builtins.str | __main__.D"

[case testBrokenClassUsingItselfAsTypeVarNoCrash]
from typing import Generic

class C(Generic[C]): # E: Free type variable expected in Generic[...] \
# E: Cannot resolve name "C" (possible cyclic definition)
pass

class D(Generic[E]): # E: Free type variable expected in Generic[...] \
# E: Cannot resolve name "E" (possible cyclic definition)
pass

class E(Generic[DD]): # E: Free type variable expected in Generic[...] \
# E: Cannot resolve name "DD" (possible cyclic definition)
pass

DD = D # E: Cannot resolve name "DD" (possible cyclic definition)
6 changes: 6 additions & 0 deletions test-data/unit/check-python312.test
Original file line number Diff line number Diff line change
Expand Up @@ -2438,3 +2438,9 @@ def test[*Us](*xs: *Us) -> None:
# TODO: we should erase last_known_values from Parameters.
reveal_type(print_args(2, *xs, 4)) # N: Revealed type is "__main__.C[[Literal[2]?, *args: *tuple[*Us, Literal[4]?]], tuple[Literal[2]?, *Us, Literal[4]?]]"
[builtins fixtures/paramspec.pyi]

[case testBrokenClassUsingItselfAsTypeVarNoCrashNewSyntax]
class C[C]:
x: C
c: C[int]
reveal_type(c.x) # N: Revealed type is "builtins.int"
Loading