Skip to content

Commit 4e0e763

Browse files
Morgan BartholomewKotlinIsland
authored andcommitted
Render star args in error messages properly
1 parent bc4ea04 commit 4e0e763

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Basedmypy Changelog
22

33
## [Unreleased]
4+
### Fixes
5+
- Render star args in error messages properly (#551)
46

57
## [2.2.1]
68
### Fixes

mypy/messages.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2484,10 +2484,14 @@ def format_callable_args(
24842484
arg_strings.append(f"{arg_name}: {format(arg_type)} = ...")
24852485
continue
24862486
elif arg_kind is ARG_STAR:
2487-
arg_strings.append(f"*{arg_name}: {format(arg_type)}")
2487+
arg_strings.append(
2488+
f"*{arg_name}: {format(arg_type)}" if arg_name else f"*{format(arg_type)}"
2489+
)
24882490
continue
24892491
elif arg_kind is ARG_STAR2:
2490-
arg_strings.append(f"**{arg_name}: {format(arg_type)}")
2492+
arg_strings.append(
2493+
f"**{arg_name}: {format(arg_type)}" if arg_name else f"**{format(arg_type)}"
2494+
)
24912495
continue
24922496
if arg_kind == ARG_POS and arg_name is None or verbosity == 0 and arg_kind.is_positional():
24932497
arg_strings.append(format(arg_type))

mypy_self_check.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ allow_any_decorated = True
1717
no_warn_unreachable = True
1818
implicit_reexport = True
1919
disallow_redefinition = True
20-
disable_error_code = truthy-bool, no-untyped-usage, possibly-undefined
20+
disable_error_code = truthy-bool, no-untyped-usage, possibly-undefined, explicit-override
2121
bare_literals = True
2222
show_error_code_links = True
2323

test-data/unit/check-based-type-render.test

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,16 @@ b = 1 # E: Incompatible types in assignment (expression has type "int", variabl
7979
def foo(): ...
8080
reveal_type(foo) # N: Revealed type is "def () -> None"
8181
foo = 1 # E: Incompatible types in assignment (expression has type "int", variable has type "() -> None") [assignment]
82+
83+
84+
[case testRenderErrorStar]
85+
from typing import Callable, ParamSpec
86+
87+
P = ParamSpec("P")
88+
89+
def f(fn: Callable[P, None]): ...
90+
f(1) # E: Argument 1 to "f" has incompatible type "int"; expected "(*Never, **Never) -> None" [arg-type]
91+
def f2(*args: int, **kwargs: str): ...
92+
a = f2
93+
a = 1 # E: Incompatible types in assignment (expression has type "int", variable has type "(*args: int, **kwargs: str) -> None") [assignment]
94+
[builtins fixtures/tuple.pyi]

0 commit comments

Comments
 (0)