Skip to content
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

false error with simple nested structure #17143

Open
zoranbosnjak opened this issue Apr 19, 2024 · 0 comments
Open

false error with simple nested structure #17143

zoranbosnjak opened this issue Apr 19, 2024 · 0 comments
Labels
bug mypy got something wrong

Comments

@zoranbosnjak
Copy link

Bug Report

mypy reports error where it is not suppose to.

To Reproduce

from typing import *                                                                                       
                                                                                                           
# types                                                                                                    
MyDict = TypedDict('MyDict', {"a" : int, "b" : str}, total=False)                                          
MyUnion = Union[                                                                                           
    Tuple[Literal["arg_int"], int],                                                                        
    Tuple[Literal["arg_str"], str],                                                                        
    Tuple[Literal["arg_dict"], MyDict]                                                                     
]                                                                                                          
                                                                                                           
# variables                                                                                                
var1 : MyUnion = ('arg_int', 1)                                                                            
var2 : MyUnion = ('arg_str', 'test')                                                                       
var3 : MyUnion = ('arg_dict', {'a': 1})    

Expected Behavior

No error is expected in this case.

Actual Behavior

The following error is reported:

error: Incompatible types in assignment (expression has type "tuple[str, dict[str, int]]", variable has type "tuple[Literal['arg_int'], int] | tuple[Literal['arg_str'], str] | tuple[Literal['arg_dict'], MyDict]")  [assignment]
Found 1 error in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: 1.9.0
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.11.8

Also tryed with mypy playground with all latest versions and got the same result.

@zoranbosnjak zoranbosnjak added the bug mypy got something wrong label Apr 19, 2024
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

1 participant