Skip to content

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

Closed as not planned
@denballakh

Description

@denballakh
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions