Skip to content

Commit 2c499d5

Browse files
Update printing for Callables
1 parent 411e1f1 commit 2c499d5

File tree

1 file changed

+6
-20
lines changed

1 file changed

+6
-20
lines changed

mypy/messages.py

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@
2424
from mypy.errorcodes import ErrorCode
2525
from mypy.errors import ErrorInfo, Errors, ErrorWatcher
2626
from mypy.nodes import (
27-
ARG_NAMED,
28-
ARG_NAMED_OPT,
29-
ARG_OPT,
3027
ARG_POS,
3128
ARG_STAR,
3229
ARG_STAR2,
@@ -112,17 +109,6 @@
112109
"typing.cast",
113110
}
114111

115-
116-
ARG_CONSTRUCTOR_NAMES: Final = {
117-
ARG_POS: "Arg",
118-
ARG_OPT: "DefaultArg",
119-
ARG_NAMED: "NamedArg",
120-
ARG_NAMED_OPT: "DefaultNamedArg",
121-
ARG_STAR: "VarArg",
122-
ARG_STAR2: "KwArg",
123-
}
124-
125-
126112
# Map from the full name of a missing definition to the test fixture (under
127113
# test-data/unit/fixtures/) that provides the definition. This is used for
128114
# generating better error messages when running mypy tests only.
@@ -2039,6 +2025,7 @@ def report_non_method_protocol(
20392025
def note_call(
20402026
self, subtype: Type, call: Type, context: Context, *, code: ErrorCode | None
20412027
) -> None:
2028+
# breakpoint()
20422029
self.note(
20432030
'"{}.__call__" has type {}'.format(
20442031
format_type_bare(subtype, self.options),
@@ -2487,11 +2474,10 @@ def format_callable_args(
24872474
if arg_kind == ARG_POS and arg_name is None or verbosity == 0 and arg_kind.is_positional():
24882475
arg_strings.append(format(arg_type))
24892476
else:
2490-
constructor = ARG_CONSTRUCTOR_NAMES[arg_kind]
24912477
if arg_kind.is_star() or arg_name is None:
2492-
arg_strings.append(f"{constructor}({format(arg_type)})")
2478+
arg_strings.append(f"{format(arg_type)}")
24932479
else:
2494-
arg_strings.append(f"{constructor}({format(arg_type)}, {repr(arg_name)})")
2480+
arg_strings.append(f"{arg_name}: {format(arg_type)}")
24952481

24962482
return ", ".join(arg_strings)
24972483

@@ -2709,14 +2695,14 @@ def format_literal_value(typ: LiteralType) -> str:
27092695
else:
27102696
return_type = format(func.ret_type)
27112697
if func.is_ellipsis_args:
2712-
return f"Callable[..., {return_type}]"
2698+
return f"(..., {return_type})"
27132699
param_spec = func.param_spec()
27142700
if param_spec is not None:
2715-
return f"Callable[{format(param_spec)}, {return_type}]"
2701+
return f"({format(param_spec)}, {return_type})"
27162702
args = format_callable_args(
27172703
func.arg_types, func.arg_kinds, func.arg_names, format, verbosity
27182704
)
2719-
return f"Callable[[{args}], {return_type}]"
2705+
return f"({args}) -> {return_type}"
27202706
else:
27212707
# Use a simple representation for function types; proper
27222708
# function types may result in long and difficult-to-read

0 commit comments

Comments
 (0)