Bug Report
Swapping the variables doesn't seem to make mypy swap their types and the second variable is left with its type as before the swap.
Changing the example below to use a temp variable fixes the issue:
tmp=aa, b=b, tmpreveal_type(a) # note: Revealed type is "test.Sub1"reveal_type(b) # note: Revealed type is "test.Sub2"
To Reproduce
classBase:
passclassSub1(Base):
passclassSub2(Base):
passdeff(a: Base, b: Base) ->None:
ifisinstance(b, Sub1) andisinstance(a, Sub2):
a, b=b, areveal_type(a) # note: Revealed type is "test.Sub1"reveal_type(b) # note: Revealed type is "test.Sub1"
Expected Behavior
Type of b is Sub2 after the swap.
Actual Behavior
Type of b is Sub1 after the swap.
Your Environment
- Mypy version used: mypy 2.2.0+dev.52de0c739d2f066ea06fa9a886bc8fcc9fa079c6
- Mypy command-line flags: None
- Mypy configuration options from
mypy.ini (and other config files): None - Python version used: 3.13.5
Bug Report
Swapping the variables doesn't seem to make mypy swap their types and the second variable is left with its type as before the swap.
Changing the example below to use a temp variable fixes the issue:
To Reproduce
Expected Behavior
Type of
bisSub2after the swap.Actual Behavior
Type of
bisSub1after the swap.Your Environment
mypy.ini(and other config files): None