Skip to content

Unexpected type inference changes related to enum value attributes #12051

Closed
@JukkaL

Description

@JukkaL

In this example, the behavior changed in #11962:

from enum import IntEnum
from typing import Any

class C(IntEnum):
    X = 0
    Y = 1
    Z = 2

def f1(c: C) -> None:
    x = {'x': c.value}
    # Old: builtins.dict[builtins.str*, builtins.int*]
    # New: builtins.dict[builtins.str*, Union[builtins.int, builtins.int, builtins.int]]
    reveal_type(x)

def f2(c: C, a: Any) -> None:
    x = {'x': c.value, 'y': a}
    # Old: builtins.dict[builtins.str*, Any]
    # New: builtins.dict[builtins.str*, Union[Any, builtins.int, builtins.int, builtins.int]]
    reveal_type(x)

These seem like regressions. The duplicate int types in unions seem like an unrelated issue that #11962 exposed. In some cases it can result in unions with dozens of items, which look pretty confusing. I'm not sure yet whether the second change is an issue with #11962 or something else.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions