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

False negative in isinstance(var, x) when x have x.__instancecheck__ #13063

Closed
denballakh opened this issue Jul 3, 2022 · 1 comment
Closed
Labels
bug mypy got something wrong

Comments

@denballakh
Copy link
Contributor

from typing import Any
class X:
    def __instancecheck__(cls, x: Any) -> bool:
        return False
x: X = X()
var: Any = 123
if isinstance(var, x): # Argument 2 to "isinstance" has incompatible type "X"; expected "Union[type, UnionType, Tuple[Union[type, UnionType, Tuple[Any, ...]], ...]]"
    reveal_type(var) # Any
else:
    reveal_type(var) # Any

Expected Behavior

No errors. First reveal_type should reveal (I honestly don't know what should be here, maybe "x" or something like "InstanceOf[X]"?), second - Any

Actual Behavior
Argument 2 to "isinstance" has incompatible type "X"; expected "Union[huge union]" error. Both reveal_type's reveals Any
At runtime i get no error.

My Environment

  • mypy 0.961 (compiled: no)
  • no command-line flags, no config file
  • CPython 3.10.4
  • Windows 10
@denballakh denballakh added the bug mypy got something wrong label Jul 3, 2022
@AlexWaygood
Copy link
Member

Duplicate of #12974

@AlexWaygood AlexWaygood marked this as a duplicate of #12974 Jul 3, 2022
@AlexWaygood AlexWaygood closed this as not planned Won't fix, can't repro, duplicate, stale Jul 3, 2022
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