Skip to content

Commit cf2e404

Browse files
authored
stubgen: fix crash with PEP 604 union in typevar bound (#14557)
Fixes #14533
1 parent f31d162 commit cf2e404

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

mypy/stubgen.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
MemberExpr,
9696
MypyFile,
9797
NameExpr,
98+
OpExpr,
9899
OverloadedFuncDef,
99100
Statement,
100101
StrExpr,
@@ -402,6 +403,9 @@ def visit_list_expr(self, node: ListExpr) -> str:
402403
def visit_ellipsis(self, node: EllipsisExpr) -> str:
403404
return "..."
404405

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

406410
class ImportTracker:
407411
"""Record necessary imports during stub generation."""

test-data/unit/stubgen.test

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2734,3 +2734,12 @@ class Some:
27342734
def __int__(self) -> int: ...
27352735
def __float__(self) -> float: ...
27362736
def __index__(self) -> int: ...
2737+
2738+
2739+
[case testTypeVarPEP604Bound]
2740+
from typing import TypeVar
2741+
T = TypeVar("T", bound=str | None)
2742+
[out]
2743+
from typing import TypeVar
2744+
2745+
T = TypeVar('T', bound=str | None)

0 commit comments

Comments
 (0)