Skip to content

Commit

Permalink
Fix forward reference in type alias bound
Browse files Browse the repository at this point in the history
  • Loading branch information
JukkaL committed May 15, 2024
1 parent ef1b473 commit 4819d60
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 3 additions & 2 deletions mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -5219,8 +5219,9 @@ def visit_match_stmt(self, s: MatchStmt) -> None:
def visit_type_alias_stmt(self, s: TypeAliasStmt) -> None:
self.statement = s
type_params = self.push_type_args(s.type_args, s)
# TODO: defer as needed
assert type_params is not None, "forward references in type aliases not implemented"
if type_params is None:
self.defer(s)
return
all_type_params_names = [p.name for p in s.type_args]

try:
Expand Down
5 changes: 5 additions & 0 deletions test-data/unit/check-python312.test
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,11 @@ type B = int + str # E: Invalid type alias: expression is not a valid type
b: B
reveal_type(b) # N: Revealed type is "Any"

[case testPEP695TypeAliasBoundForwardReference]
# mypy: enable-incomplete-feature=NewGenericSyntax
type B[T: Foo] = list[T]
class Foo: pass

[case testPEP695UpperBound]
# flags: --enable-incomplete-feature=NewGenericSyntax

Expand Down

0 comments on commit 4819d60

Please sign in to comment.