Skip to content

Commit 2cb296a

Browse files
author
theodoreando
committed
extract condition of if arg is should use complex formatting
1 parent d94a2a9 commit 2cb296a

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

mypy/messages.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2530,6 +2530,15 @@ def quote_type_string(type_string: str) -> str:
25302530
return f'"{type_string}"'
25312531

25322532

2533+
def should_format_arg_as_type(arg_kind: ArgKind, arg_name: str | None, verbosity: int) -> bool:
2534+
"""
2535+
Determine whether a function argument should be formatted as its Type or with name.
2536+
"""
2537+
return (arg_kind == ARG_POS and arg_name is None) or (
2538+
verbosity == 0 and arg_kind.is_positional()
2539+
)
2540+
2541+
25332542
def format_callable_args(
25342543
arg_types: list[Type],
25352544
arg_kinds: list[ArgKind],
@@ -2540,7 +2549,7 @@ def format_callable_args(
25402549
"""Format a bunch of Callable arguments into a string"""
25412550
arg_strings = []
25422551
for arg_name, arg_type, arg_kind in zip(arg_names, arg_types, arg_kinds):
2543-
if arg_kind == ARG_POS and arg_name is None or verbosity == 0 and arg_kind.is_positional():
2552+
if should_format_arg_as_type(arg_kind, arg_name, verbosity):
25442553
arg_strings.append(format(arg_type))
25452554
else:
25462555
constructor = ARG_CONSTRUCTOR_NAMES[arg_kind]
@@ -2769,10 +2778,8 @@ def format_literal_value(typ: LiteralType) -> str:
27692778
# Use pretty format (def-style) for complex signatures with named, optional, or star args.
27702779
# Use compact Callable[[...], ...] only for signatures with all simple positional args.
27712780
has_complex_args = any(
2772-
not (
2773-
(kind == ARG_POS and name is None) or (verbosity == 0 and kind.is_positional())
2774-
)
2775-
for name, kind in zip(func.arg_names, func.arg_kinds)
2781+
not should_format_arg_as_type(kind, name, verbosity)
2782+
for kind, name in zip(func.arg_kinds, func.arg_names)
27762783
)
27772784
if use_pretty_callable and has_complex_args:
27782785
return pretty_callable(func, options)

0 commit comments

Comments
 (0)