Skip to content

Commit e38a78e

Browse files
committed
Fix: suppress Foo[...] suggestion when annotation uses keyword args - Fixes #16506
1 parent 9790459 commit e38a78e

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

mypy/fastparse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1957,7 +1957,7 @@ def visit_Call(self, e: Call) -> Type:
19571957

19581958
if not isinstance(self.parent(), ast3.List):
19591959
note = None
1960-
if constructor:
1960+
if constructor and not e.keywords and len(e.args) == 1:
19611961
note = "Suggestion: use {0}[...] instead of {0}(...)".format(constructor)
19621962
return self.invalid_type(e, note=note)
19631963
if not constructor:

test-data/unit/check-fastparse.test

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,15 @@ def f(a: Foo(int)) -> int:
207207
main:7: error: Invalid type comment or annotation
208208
main:7: note: Suggestion: use Foo[...] instead of Foo(...)
209209

210+
[case testFasterParseTypeErrorCustomNoSuggestionForKeywordArgs_no_native_parse]
211+
from typing import TypeVar, Generic
212+
T = TypeVar('T')
213+
class Foo(Generic[T]):
214+
pass
215+
x: Foo(arg=1)
216+
[out]
217+
main:5: error: Invalid type comment or annotation
218+
210219
[case testFastParseMatMul]
211220

212221
from typing import Any

0 commit comments

Comments
 (0)