diff --git a/mypy/stubdoc.py b/mypy/stubdoc.py index e99204f3ade5..0da93b4e2477 100644 --- a/mypy/stubdoc.py +++ b/mypy/stubdoc.py @@ -21,7 +21,7 @@ Sig: _TypeAlias = tuple[str, str] -_TYPE_RE: Final = re.compile(r"^[a-zA-Z_][\w\[\], .\"\']*(\.[a-zA-Z_][\w\[\], ]*)*$") +_TYPE_RE: Final = re.compile(r"^[a-zA-Z_][\w\[\], .\"\'|]*(\.[a-zA-Z_][\w\[\], ]*)*$") _ARG_NAME_RE: Final = re.compile(r"\**[A-Za-z_][A-Za-z0-9_]*$") diff --git a/mypy/test/teststubgen.py b/mypy/test/teststubgen.py index dffa1aa80c5d..83693bebd91e 100644 --- a/mypy/test/teststubgen.py +++ b/mypy/test/teststubgen.py @@ -1405,6 +1405,9 @@ def test_is_valid_type(self) -> None: assert is_valid_type("Literal[True]") assert is_valid_type("Literal[Color.RED]") assert is_valid_type("Literal[None]") + assert is_valid_type("str | int") + assert is_valid_type("dict[str, int] | int") + assert is_valid_type("tuple[str, ...]") assert is_valid_type( 'Literal[26, 0x1A, "hello world", b"hello world", u"hello world", True, Color.RED, None]' )