(🐞) Failure to narrow lambdas when using Protocol
with __call__
#16797
Labels
bug
mypy got something wrong
Protocol
with __call__
#16797
Bug Report
Mypy fails to narrow lambdas and detect errors when using a
Protocol
with a__call__
method, in situations where using the equivalentCallable
formulation results in narrowing and error detection.To Reproduce
In the following snippet, type narrowing is performed on the lambda function passed to the
validator
argument ofvalidate10
, resulting in the implementation typo being caught by Mypy:The following snippet is essentially equivalent to the above, but using
Protocol
in place ofCallable
. The type of the lambda function is no longer narrowed, and the implementation typo is not caught:I would expect the narrowing behaviour in the two snippets to be the same (or close enough).
Please note that the issue persists even when the type variable is removed:
Pylance/Pyright (strict) detects the typo in all cases.
Your Environment
The text was updated successfully, but these errors were encountered: