Thanks to visit codestin.com
Credit goes to github.com

Skip to content

nested isinstances lose type information #10146

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

Open
Akuli opened this issue Feb 27, 2021 · 2 comments
Open

nested isinstances lose type information #10146

Akuli opened this issue Feb 27, 2021 · 2 comments
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code topic-join-v-union Using join vs. using unions topic-type-narrowing Conditional type narrowing / binder topic-union-types

Comments

@Akuli
Copy link
Contributor

Akuli commented Feb 27, 2021

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
@Akuli Akuli added the bug mypy got something wrong label Feb 27, 2021
@JukkaL JukkaL added false-positive mypy gave an error on correct code topic-union-types labels Mar 5, 2021
@JukkaL
Copy link
Collaborator

JukkaL commented Mar 5, 2021

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

@AlexWaygood AlexWaygood added the topic-type-narrowing Conditional type narrowing / binder label Apr 4, 2022
@erictraut
Copy link

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
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code topic-join-v-union Using join vs. using unions topic-type-narrowing Conditional type narrowing / binder topic-union-types
Projects
None yet
Development

No branches or pull requests

5 participants