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

set.__and__ false-positive involving generic inference #15462

Open
cebtenzzre opened this issue Jun 18, 2023 · 0 comments
Open

set.__and__ false-positive involving generic inference #15462

cebtenzzre opened this issue Jun 18, 2023 · 0 comments
Labels
bug mypy got something wrong

Comments

@cebtenzzre
Copy link

Bug Report

The way mypy does type inference breaks calling a generic function on the right side of set.__and__, because it takes an argument of type AbstractSet[object]. It seems like it is propagating 'object' instead of the more specific type and then complaining when that does not work.

I reported this as a comment on #5738, but this is apparently a different issue because this problem was not fixed when that issue was closed.

To Reproduce

from typing import TypeVar

T = TypeVar('T')

def identity(x: set[T]) -> set[T]:
    return x

x = {0, 1}

print({0} & identity(x))

Actual Behavior

$ mypy repr.py
repr.py:10: error: Argument 1 to "identity" has incompatible type "set[int]"; expected "set[object]"  [arg-type]
Found 1 error in 1 file (checked 1 source file)

$ mypy --new-type-inference repr.py
repr.py:10: error: Argument 1 to "identity" has incompatible type "set[int]"; expected "set[object]"  [arg-type]
Found 1 error in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: mypy 1.5.0+dev.0873230ee60461110bd7bfde7ca3886878aae389 (compiled: no)
  • Python version used: Python 3.11.3
@cebtenzzre cebtenzzre added the bug mypy got something wrong label Jun 18, 2023
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

1 participant