Skip to content

Commit 287a344

Browse files
committed
Don't use regex in format_type() path
1 parent ef96fa3 commit 287a344

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

mypy/messages.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2517,11 +2517,10 @@ def iteration_dependent_errors(self, iter_errors: IterationDependentErrors) -> N
25172517

25182518
def quote_type_string(type_string: str) -> str:
25192519
"""Quotes a type representation for use in messages."""
2520-
no_quote_regex = r"^<(tuple|union): \d+ items>$"
25212520
if (
25222521
type_string in ["Module", "overloaded function", "<deleted>"]
25232522
or type_string.startswith("Module ")
2524-
or re.match(no_quote_regex, type_string) is not None
2523+
or short_tuple_or_union(type_string)
25252524
or type_string.endswith("?")
25262525
):
25272526
# Messages are easier to read if these aren't quoted. We use a
@@ -2530,6 +2529,12 @@ def quote_type_string(type_string: str) -> str:
25302529
return f'"{type_string}"'
25312530

25322531

2532+
def short_tuple_or_union(typ: str) -> bool:
2533+
if not (typ.startswith("<tuple ") or typ.startswith("<union ")):
2534+
return False
2535+
return typ.endswith(" item>")
2536+
2537+
25332538
def format_callable_args(
25342539
arg_types: list[Type],
25352540
arg_kinds: list[ArgKind],

0 commit comments

Comments
 (0)