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
mypy doesn't understand the signature compatibility between functions when determining valid uses in lists. This means mypy can miss type errors.
To Reproduce
The following code type checks despite containing a type error that will lead to runtime failure. The expectation was that appending to the list will show a type error or warning for the incompatible signatures.
funclist= [lambdax: print(1)]
funclist+= [lambdak: print(2)] # incompatible signature, but type not widened and no errorreveal_type(funclist) # builtins.list[def (x: Any)]funclist[1](x=4) # this will error at runtime because of a typing mistake
Expected Behavior
Type error. I compared to pyright and pyright does show a type error for the incompatible signatures. Other possible behaviors would be to widen the type of funclist on line 1 or 2 to no longer think the first argument has keyword variable named x, but this is probably a bit odd/inconsistent. In this case mypy would be able to throw an error on line 4 with the keyword argument usage. Normally you would need to annotate funclist when it's defined if you wanted the wider behavior.
Actual Behavior
no type error
Your Environment
Mypy version used: 0.920
Mypy command-line flags: none
Mypy configuration options from mypy.ini (and other config files): none
Python version used: 3.10
Operating system and version: Gentoo/Linux stable
The text was updated successfully, but these errors were encountered:
Bug Report
mypy doesn't understand the signature compatibility between functions when determining valid uses in lists. This means mypy can miss type errors.
To Reproduce
The following code type checks despite containing a type error that will lead to runtime failure. The expectation was that appending to the list will show a type error or warning for the incompatible signatures.
Expected Behavior
Type error. I compared to pyright and pyright does show a type error for the incompatible signatures. Other possible behaviors would be to widen the type of
funclist
on line 1 or 2 to no longer think the first argument has keyword variable namedx
, but this is probably a bit odd/inconsistent. In this case mypy would be able to throw an error on line 4 with the keyword argument usage. Normally you would need to annotatefunclist
when it's defined if you wanted the wider behavior.Actual Behavior
no type error
Your Environment
mypy.ini
(and other config files): noneThe text was updated successfully, but these errors were encountered: