Skip to content

Commit b9745ef

Browse files
committed
stubgen: Fix valid type detection to allow pipe unions
1 parent 256cf68 commit b9745ef

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

mypy/stubdoc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
Sig: _TypeAlias = tuple[str, str]
2222

2323

24-
_TYPE_RE: Final = re.compile(r"^[a-zA-Z_][\w\[\], .\"\']*(\.[a-zA-Z_][\w\[\], ]*)*$")
24+
_TYPE_RE: Final = re.compile(r"^[a-zA-Z_][\w\[\], .\"\'|]*(\.[a-zA-Z_][\w\[\], ]*)*$")
2525
_ARG_NAME_RE: Final = re.compile(r"\**[A-Za-z_][A-Za-z0-9_]*$")
2626

2727

mypy/test/teststubgen.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,6 +1405,8 @@ def test_is_valid_type(self) -> None:
14051405
assert is_valid_type("Literal[True]")
14061406
assert is_valid_type("Literal[Color.RED]")
14071407
assert is_valid_type("Literal[None]")
1408+
assert is_valid_type("str | int")
1409+
assert is_valid_type("dict[str, int] | int")
14081410
assert is_valid_type(
14091411
'Literal[26, 0x1A, "hello world", b"hello world", u"hello world", True, Color.RED, None]'
14101412
)

0 commit comments

Comments
 (0)