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

Seemingly correct type narrowing, but still incompatible type #13744

Closed
hwong557 opened this issue Sep 26, 2022 · 4 comments
Closed

Seemingly correct type narrowing, but still incompatible type #13744

hwong557 opened this issue Sep 26, 2022 · 4 comments
Labels
bug mypy got something wrong topic-match-statement Python 3.10's match statement topic-named-tuple

Comments

@hwong557
Copy link

Bug Report

Mypy seems to type narrow correctly, but still throws an error when trying to add to a set.

To Reproduce

Gist URL: https://gist.github.com/c10befca044d78713b96a9706ac355b2
Playground URL: https://mypy-play.net/?mypy=master&python=3.10&gist=c10befca044d78713b96a9706ac355b2

Expected Behavior

No error.

Actual Behavior

main.py:15: error: Argument 1 to "add" of "set" has incompatible type "Data"; expected "Data"
Found 1 error in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: mypy 0.990+dev.780534b13722b7b0422178c049a1cbbf4ea4255b (compiled: no)
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.10.7
@hwong557 hwong557 added the bug mypy got something wrong label Sep 26, 2022
@JelleZijlstra
Copy link
Member

Here's an interesting variation: https://mypy-play.net/?mypy=master&python=3.10&gist=be6708082fc74cb9e2577840877b1741. If you declare a variable as of type Data directly, its revealed type is "Tuple[builtins.str, builtins.int, fallback=__main__.Data]" instead of __main__.Data.

@sterliakov
Copy link
Collaborator

This is resolved (fails up to and including 1.6.1, works in 1.7.0 through current master). Bisects to seemingly unrelated #249f3f (PR #16053)

@hauntsaninja
Copy link
Collaborator

Thanks, yeah I guess subtyping changes in that PR help

@ilevkivskyi
Copy link
Member

Actually it looks like #16053 introduced a subtle bug in subtyping, this is why it fixed this issue. I will at fixing myself soon, I am not going to re-open this, as there is a conveniently open duplicate #15299, that also looks fixed because of the subtyping bug.

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-match-statement Python 3.10's match statement topic-named-tuple
Projects
None yet
Development

No branches or pull requests

5 participants