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

Confusing error from bidirectional inference? #18297

Open
alicederyn opened this issue Dec 16, 2024 · 1 comment
Open

Confusing error from bidirectional inference? #18297

alicederyn opened this issue Dec 16, 2024 · 1 comment
Labels
bug mypy got something wrong topic-type-context Type context / bidirectional inference

Comments

@alicederyn
Copy link

Bug Report

When the return type from dict.pop is incompatible with existing variable type, mypy gives an arg-type error when an assignment error seems more intuitive.

(Originally noted in #10152)

To Reproduce

values_by_name = {"one": 1, "two": 2}
value: int
value = values_by_name.pop("one", None)

https://gist.github.com/mypy-play/972f4514ebe5620ece42583192907f62

Expected Behavior

example.py:3: error: Incompatible types in assignment (expression has type "int | None", variable has type "int")  [assignment]

Actual Behavior

example.py:3: error: Argument 2 to "pop" of "dict" has incompatible type "None"; expected "int"  [arg-type]

Note: this is a lot more surprising if value has this type because it was unintentionally reused from some code further up, e.g. if you're using value in a loop or something; it can be very difficult to spot what the real error is. See #10152 (comment) for example.

Your Environment

  • Mypy version used: 1.13.0
  • Mypy command-line flags: None
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: 3.12.2
@alicederyn alicederyn added the bug mypy got something wrong label Dec 16, 2024
@alicederyn
Copy link
Author

This may be the same issue as #14773 and #15408 ?

@brianschubert brianschubert added the topic-type-context Type context / bidirectional inference label Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-type-context Type context / bidirectional inference
Projects
None yet
Development

No branches or pull requests

2 participants