Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mypy doesn't understand function signature compatibility #11807

Open
GBeauregard opened this issue Dec 20, 2021 · 1 comment
Open

mypy doesn't understand function signature compatibility #11807

GBeauregard opened this issue Dec 20, 2021 · 1 comment
Labels
bug mypy got something wrong

Comments

@GBeauregard
Copy link

GBeauregard commented Dec 20, 2021

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.

funclist = [lambda x: print(1)]
funclist += [lambda k: print(2)]  # incompatible signature, but type not widened and no error
reveal_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
@GBeauregard GBeauregard added the bug mypy got something wrong label Dec 20, 2021
@DanielNoord
Copy link

DanielNoord commented Aug 30, 2023

Duplicate of #1013, see also #14639.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

2 participants