Skip to content

Commit

Permalink
Add more precise error message for Callable annotation (#12518)
Browse files Browse the repository at this point in the history
Adds a more precise error message for a Callable annotation, if the
option --disallow-any-generics (part of --strict mode) has been used.
The suggestion in the old message was incorrect in this scenario.

Fixes #11757
  • Loading branch information
frerikandriessen authored May 7, 2022
1 parent 4f07c79 commit 269adee
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion mypy/typeanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,10 @@ def analyze_callable_type(self, t: UnboundType) -> Type:
return AnyType(TypeOfAny.from_error)
ret = maybe_ret
else:
self.fail('Please use "Callable[[<parameters>], <return type>]" or "Callable"', t)
if self.options.disallow_any_generics:
self.fail('Please use "Callable[[<parameters>], <return type>]"', t)
else:
self.fail('Please use "Callable[[<parameters>], <return type>]" or "Callable"', t)
return AnyType(TypeOfAny.from_error)
assert isinstance(ret, CallableType)
return ret.accept(self)
Expand Down

0 comments on commit 269adee

Please sign in to comment.