diff --git a/mypy/stubgen.py b/mypy/stubgen.py index 8c7e24504270..bed552c3e214 100755 --- a/mypy/stubgen.py +++ b/mypy/stubgen.py @@ -95,6 +95,7 @@ MemberExpr, MypyFile, NameExpr, + OpExpr, OverloadedFuncDef, Statement, StrExpr, @@ -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.""" diff --git a/test-data/unit/stubgen.test b/test-data/unit/stubgen.test index 8467271e5593..009db553237f 100644 --- a/test-data/unit/stubgen.test +++ b/test-data/unit/stubgen.test @@ -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)