Skip to content

can't refine Dict[str, str] with isinstance check #9783

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

Closed
sbdchd opened this issue Dec 6, 2020 · 1 comment
Closed

can't refine Dict[str, str] with isinstance check #9783

sbdchd opened this issue Dec 6, 2020 · 1 comment
Labels
bug mypy got something wrong

Comments

@sbdchd
Copy link
Contributor

sbdchd commented Dec 6, 2020

Bug Report

Refining x: Dict[Any, Any] works via isinstance(x, dict), but doesn't for x: Dict[str, str]

To Reproduce

from typing import Dict, Any

z: Dict[str, str]
if not isinstance(z, dict):
    reveal_type(z) # note: Revealed type is 'builtins.dict[builtins.str, builtins.str]'

x: Dict[Any, Any]
if not isinstance(x, dict):
    reveal_type(x) # error: Statement is unreachable

Expected Behavior

Dict[str, str] would be refined such that mypy gives a statement is unreachable error

Actual Behavior

Dict[str, str] doesn't get refined

Your Environment

  • Mypy version used: 0.7.9
  • Mypy command-line flags: --warn-unreachable
  • Mypy configuration options from mypy.ini (and other config files): N/A
  • Python version used: 3.9
  • Operating system and version: linux
@sbdchd sbdchd added the bug mypy got something wrong label Dec 6, 2020
@AlexWaygood
Copy link
Member

Can't reproduce on 0.940+

kodiakhq bot pushed a commit to sbdchd/django-types that referenced this issue Apr 3, 2022
Since python/mypy#9783 is fixed, we can finally uncomment the refine checks that were not working previously.

Also, this PR fixes all remaining issues for the latest versions of both mypy and pyright.
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