basedmypy icon indicating copy to clipboard operation
basedmypy copied to clipboard

Wacky `dict` `reveal_type` moment

Open KotlinIsland opened this issue 1 year ago • 1 comments

a = reveal_type({ # Revealed type is "dict['C' | 'D', None]"
    "A": None,
    "B": None,
    "C": None,
    "D": None,
})
reveal_type(a)  # Revealed type is "dict[str, None]"

KotlinIsland avatar Apr 19 '24 02:04 KotlinIsland

It gets even weirder with different numbers of items, and when mixing types:

reveal_type({ # Revealed type is "dict[str, int]"
    "A": 1,
})

reveal_type({ # Revealed type is "dict['A' | 'B', 1 | 2]"
    "A": 1,
    "B": 2,
})

reveal_type({ # Revealed type is "dict[str, 1 | 2]"
    "A": 1,
    "B": 1,
    "C": 2,
})

reveal_type({ # Revealed type is "dict['E' | 'F', 3 | 4 | 'A']"
    "A": 1,
    "B": 2,
    "C": 3,
    "D": 4,
    "E": "A",
    "F": False,
})

Zeckie avatar Apr 19 '24 09:04 Zeckie