Skip to content

Multiple isinstance checks in if condition #900

Closed

Description

@JukkaL

Mypy should support multiple isinstance checks in a condition:

def f(x: A, y: A) -> None:
    if isinstance(x, B) and isinstance(y, B):
        # Types of both x and y should be B here, but currently only x is B
        ...

class A: pass
class B(A): pass

This is related to #473.

Activity

  1. jhance commented on Oct 10, 2015

    @jhance
    Collaborator

    I think find_isinstance_check should effectively return a tuple of Tuple[Dict[Node, Tuple[Type, Type]], int] where the int is the old kind. My impression is that the result kind, contrary to the documentation, should represent whether the condition is always true whether than rather the isinstance is always true (based on what we do in the and case currently). If thats not true, it would go inside the Dict.

  2. ecprice commented on Oct 10, 2015

    @ecprice
    Contributor

    My impression is that the result kind, contrary to the documentation, should represent whether the condition is always true whether than rather the isinstance is always true (based on what we do in the and case currently).

    Yeah, that's right. I would probably go with Tuple[Dict[Node, Type], Dict[Node, Type], int], for the return type, though.

    Actually, it might be better to be Tuple[Optional[Dict[Node, Type]], Optional[Dict[Node, Type]]] with no kind at all -- if a component is None, then that branch of the conditional cannot happen. If it's not None, then you update the binder using the component. This would avoid the need for the ISINSTANCE_ enum entirely.

  3. added 4 commits that reference this issue on Oct 11, 2015
    a02440d
    5ee32e7
    15f866c
    42b6160
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions