You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Bug Report
I'm looking into the issue with design-by-contract library icontract which heavily uses decorators to formalize contracts. For many functions and methods, the contracts involve the decorated function (or method) itself.
from icontract import ensure
@ensure(
lambda a, b, result:
result == myadd(b, a),
"Commutativity violated!"
)
def myadd(a: int, b: int) -> int:
return a + b
Mypy 0.960 says:
tests_3_10\deleteme.py:5: error: Cannot determine type of "myadd"
If I add # type: ignore:
from icontract import ensure
@ensure(
lambda a, b, result:
result == myadd(b, a), # type: ignore
"Commutativity violated!"
)
def myadd(a: int, b: int) -> int:
return a + b
mypy does not complain any more.
I was actually a bit surprised that mypy tried to infer the types in the lambda. @claudio-ebel tried a couple of fixes using casting (see his comment Parquery/icontract#243 (comment)), but none of them worked.
I am actually not sure if this is a misunderstanding on our part or a bug in mypy. Any pointers about how to resolve the issue are very much appreciated! Please let us know if you need more information, or if there is anything we can do to help to fix this.
Your Environment
Mypy version used: 0.960
Mypy command-line flags: `--strict``
Python version used: 3.10.0
The text was updated successfully, but these errors were encountered:
This is an unresolvable circular reference from a type checker's perspective. Evaluating the call to ensure() requires the evaluation of the arguments, including the lambda. But evaluating the lambda involves the evaluation of myadd, which refers to the decorated symbol.
FWIW, pyright also emits an error in this case: Type of "myadd" could not be determined because it refers to itself.
I don't think this is a bug in mypy. As I explained above, this is an unresolvable circular dependency from the perspective of a static type checker. I recommend closing unless you think it's worth improving the error message.
Hi mypy team,
Bug Report
I'm looking into the issue with design-by-contract library icontract which heavily uses decorators to formalize contracts. For many functions and methods, the contracts involve the decorated function (or method) itself.
See the example from the issue Parquery/icontract#243:
Mypy 0.960 says:
If I add
# type: ignore
:mypy does not complain any more.
I was actually a bit surprised that mypy tried to infer the types in the lambda. @claudio-ebel tried a couple of fixes using casting (see his comment Parquery/icontract#243 (comment)), but none of them worked.
I am actually not sure if this is a misunderstanding on our part or a bug in mypy. Any pointers about how to resolve the issue are very much appreciated! Please let us know if you need more information, or if there is anything we can do to help to fix this.
Your Environment
The text was updated successfully, but these errors were encountered: