From e38a78e0327613aa9b3c8793f408fabe6bace441 Mon Sep 17 00:00:00 2001 From: Vincent Date: Thu, 9 Apr 2026 15:32:01 -0400 Subject: [PATCH 1/2] Fix: suppress Foo[...] suggestion when annotation uses keyword args - Fixes #16506 --- mypy/fastparse.py | 2 +- test-data/unit/check-fastparse.test | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/mypy/fastparse.py b/mypy/fastparse.py index e85b8fffaf9e9..b4f48ee1b7ad3 100644 --- a/mypy/fastparse.py +++ b/mypy/fastparse.py @@ -1957,7 +1957,7 @@ def visit_Call(self, e: Call) -> Type: if not isinstance(self.parent(), ast3.List): note = None - if constructor: + if constructor and not e.keywords and len(e.args) == 1: note = "Suggestion: use {0}[...] instead of {0}(...)".format(constructor) return self.invalid_type(e, note=note) if not constructor: diff --git a/test-data/unit/check-fastparse.test b/test-data/unit/check-fastparse.test index 7ee5a9c432169..a0a0ebe91f395 100644 --- a/test-data/unit/check-fastparse.test +++ b/test-data/unit/check-fastparse.test @@ -207,6 +207,15 @@ def f(a: Foo(int)) -> int: main:7: error: Invalid type comment or annotation main:7: note: Suggestion: use Foo[...] instead of Foo(...) +[case testFasterParseTypeErrorCustomNoSuggestionForKeywordArgs_no_native_parse] +from typing import TypeVar, Generic +T = TypeVar('T') +class Foo(Generic[T]): + pass +x: Foo(arg=1) +[out] +main:5: error: Invalid type comment or annotation + [case testFastParseMatMul] from typing import Any From 344efed5b4f3d4ac23e6c9654c54defe3109341f Mon Sep 17 00:00:00 2001 From: Vincent Date: Thu, 9 Apr 2026 16:04:06 -0400 Subject: [PATCH 2/2] Refine fix: only suppress suggestion when keyword args present --- mypy/fastparse.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mypy/fastparse.py b/mypy/fastparse.py index b4f48ee1b7ad3..2415416decbac 100644 --- a/mypy/fastparse.py +++ b/mypy/fastparse.py @@ -1957,7 +1957,7 @@ def visit_Call(self, e: Call) -> Type: if not isinstance(self.parent(), ast3.List): note = None - if constructor and not e.keywords and len(e.args) == 1: + if constructor and not e.keywords: note = "Suggestion: use {0}[...] instead of {0}(...)".format(constructor) return self.invalid_type(e, note=note) if not constructor: