Skip to content

Commit

Permalink
stubgen: fix crash with PEP 604 union in typevar bound (#14557)
Browse files Browse the repository at this point in the history
Fixes #14533
  • Loading branch information
hauntsaninja authored Jan 30, 2023
1 parent f31d162 commit cf2e404
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions mypy/stubgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
MemberExpr,
MypyFile,
NameExpr,
OpExpr,
OverloadedFuncDef,
Statement,
StrExpr,
Expand Down Expand Up @@ -402,6 +403,9 @@ def visit_list_expr(self, node: ListExpr) -> str:
def visit_ellipsis(self, node: EllipsisExpr) -> str:
return "..."

def visit_op_expr(self, o: OpExpr) -> str:
return f"{o.left.accept(self)} {o.op} {o.right.accept(self)}"


class ImportTracker:
"""Record necessary imports during stub generation."""
Expand Down
9 changes: 9 additions & 0 deletions test-data/unit/stubgen.test
Original file line number Diff line number Diff line change
Expand Up @@ -2734,3 +2734,12 @@ class Some:
def __int__(self) -> int: ...
def __float__(self) -> float: ...
def __index__(self) -> int: ...


[case testTypeVarPEP604Bound]
from typing import TypeVar
T = TypeVar("T", bound=str | None)
[out]
from typing import TypeVar

T = TypeVar('T', bound=str | None)

0 comments on commit cf2e404

Please sign in to comment.