Skip to content

nested isinstances lose type information #10146

Open

Description

@Akuli

Bug Report

To Reproduce

x = object()
if isinstance(x, (int, str)):
    reveal_type(x)      # Union[int, str]
    if isinstance(x, int):
        pass
    reveal_type(x)      # object

Expected Behavior

both types revealed as Union[int, str]

Actual Behavior

object from second type

Your Environment

  • Mypy version used: latest master (0.820+dev.72ac2cee910ca61bfdf449217328b6d10b45d378)
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.7.3
  • Operating system and version: debian 10 based linux distro

Activity

  1. JukkaL commented on Mar 5, 2021

    @JukkaL
    Collaborator

    It looks like we should perhaps maintain a stack of narrowed down types (though I might be wrong).

  2. erictraut commented on Aug 12, 2023

    @erictraut

    This is another example of join vs union. It should probably be tagged as such.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions