Skip to content

Conversation

@AlexWaygood
Copy link
Member

This enum looks like it has two members, but it actually has only one, because Color.RED and Color.BLUE have the same value; Color.BLUE here is actually just an alias for Color.RED:

>>> from enum import Enum
>>> class Color(Enum):
...     RED = 1
...     BLUE = 1
...     
>>> list(Color)
[<Color.RED: 1>]
>>> Color.RED is Color.BLUE
True

ty is able to understand that, and this leads to ty failing the assertion a few lines below:

def check_expand_enum(v: Color) -> None:
ret1 = expand_enum(v)
assert_type(ret1, Literal[0, 1])

because it is able to infer that the second overload will never be taken, and therefore infers the more precise type of Literal[0] as a result of the expand_enum() call.

I don't think that's what the assertion was trying to test, so this PR updates the enum to have >1 member.

This enum looks like it has two members, but it actually has only one, because `Color.RED` and `Color.BLUE` have the same value; `Color.BLUE` here is actually just an alias for `Color.RED`:

```pycon
>>> from enum import Enum
>>> class Color(Enum):
...     RED = 1
...     BLUE = 1
...     
>>> list(Color)
[<Color.RED: 1>]
>>> Color.RED is Color.BLUE
True
```

ty is able to understand that, and this leads to ty failing the assertion a few lines below:

https://github.com/python/typing/blob/b40321ce2037f67e1976e1b03a7766636ae54dc7/conformance/tests/overloads_evaluation.py#L160-L162

because it is able to infer that the second overload will never be taken, and therefore infers the more precise type of `Literal[0]` as a result of the `expand_enum()` call.

I don't think that's what the assertion was trying to test, so this PR updates the enum to have >1 member.
@AlexWaygood AlexWaygood added the topic: conformance tests Issues with the conformance test suite label Jan 28, 2026
Copy link
Member

@carljm carljm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@carljm carljm merged commit f289ccf into main Jan 28, 2026
5 checks passed
@carljm carljm deleted the alex/color-enum branch January 28, 2026 23:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic: conformance tests Issues with the conformance test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants