Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Tuple Special Cases from Docstrings #17440

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'master' into fix-tuple-special-cases-docstrings
  • Loading branch information
InvincibleRMC committed Jun 29, 2024
commit 74bbda433600e92a746d7eef7d366de44ebad6f8
3 changes: 2 additions & 1 deletion mypy/stubdoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 20,8 @@
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\[\], ]*)*$")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So basically this giant regex matches these:

  • a
  • abc
  • a[1], b(2).c
  • a_b.c_d
  • a.b.c

_ARG_NAME_RE: Final = re.compile(r"\**[A-Za-z_][A-Za-z0-9_]*$")


Expand Down
11 changes: 11 additions & 0 deletions mypy/test/teststubgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -1389,6 1389,17 @@ def test_is_valid_type(self) -> None:
assert is_valid_type("tuple[int]")
assert is_valid_type("tuple[()]")
assert is_valid_type("tuple[int, ...]")
assert is_valid_type("Literal[26]")
assert is_valid_type("Literal[0x1A]")
assert is_valid_type('Literal["hello world"]')
assert is_valid_type('Literal[b"hello world"]')
assert is_valid_type('Literal[u"hello world"]')
assert is_valid_type("Literal[True]")
assert is_valid_type("Literal[Color.RED]")
assert is_valid_type("Literal[None]")
assert is_valid_type(
'Literal[26, 0x1A, "hello world", b"hello world", u"hello world", True, Color.RED, None]'
)
assert not is_valid_type("foo-bar")
assert not is_valid_type("x->y")
assert not is_valid_type("True")
Expand Down
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.