You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[1.16 regression] determining exhaustive match on an enum with type members #19151
changed the title [-]Regression in upcoming mypy 1.16[/-][+]Regression in upcoming mypy 1.16 - determining exhaustive match on an enum[/+]on May 26, 2025
Sure, please do. In general, don't need to ask, just put up PRs!
Obviously most principled thing to do is understand what enum actually does at runtime to differentiate the lambda case #18675 was thinking about. An ad hoc thing could be to special case type object function likes
Thanks for the go-ahead, @hauntsaninja! I’ll start digging into the issue and put up a PR as soon as I have a fix. I’ll also take a closer look at how enums behave at runtime to make sure the solution is solid. Appreciate the guidance!
@vidhyavijayan3, there's one gotcha to keep in mind when you implement this. In general, enum types can be expanded into their individual literal member types. For example, the type ValueType is equivalent to Literal[ValueType.BOOLEAN, ValueType.DATE, ValueType.DATETIME] in the code sample above. This equivalency allows you to eliminate subtypes from the literal union based on pattern matches. However, this expansion doesn't work for classes that derive from enum.Flag, so this needs to be special-cased. For more details, refer to this section of the typing spec.
Thank you very much @erictraut for pointing that out. I understand the difference between enum and enum.Flag and the need to handle enum.Flag as a special case. I will review the relevant section of the typing specification to ensure I fully grasp the details before implementing the fix. I appreciate your helpful guidance!
changed the title [-]Regression in upcoming mypy 1.16 - determining exhaustive match on an enum[/-][+][1.16 regression] determining exhaustive match on an enum with type members[/+]on May 28, 2025
Activity
[-]Regression in upcoming mypy 1.16[/-][+]Regression in upcoming mypy 1.16 - determining exhaustive match on an enum[/+]hauntsaninja commentedon May 26, 2025
Thanks for testing pre-release. Bisects to #18675 cc @sobolevn
vidhyavijayan3 commentedon May 27, 2025
Hi @delfick @hauntsaninja
Can I work on this issue ?
hauntsaninja commentedon May 27, 2025
Sure, please do. In general, don't need to ask, just put up PRs!
Obviously most principled thing to do is understand what
enumactually does at runtime to differentiate the lambda case #18675 was thinking about. An ad hoc thing could be to special case type object function likesvidhyavijayan3 commentedon May 27, 2025
Thanks for the go-ahead, @hauntsaninja! I’ll start digging into the issue and put up a PR as soon as I have a fix. I’ll also take a closer look at how enums behave at runtime to make sure the solution is solid. Appreciate the guidance!
erictraut commentedon May 27, 2025
@vidhyavijayan3, there's one gotcha to keep in mind when you implement this. In general, enum types can be expanded into their individual literal member types. For example, the type
ValueTypeis equivalent toLiteral[ValueType.BOOLEAN, ValueType.DATE, ValueType.DATETIME]in the code sample above. This equivalency allows you to eliminate subtypes from the literal union based on pattern matches. However, this expansion doesn't work for classes that derive fromenum.Flag, so this needs to be special-cased. For more details, refer to this section of the typing spec.vidhyavijayan3 commentedon May 27, 2025
Thank you very much @erictraut for pointing that out. I understand the difference between enum and enum.Flag and the need to handle enum.Flag as a special case. I will review the relevant section of the typing specification to ensure I fully grasp the details before implementing the fix. I appreciate your helpful guidance!
delfick commentedon May 28, 2025
hauntsaninja commentedon May 28, 2025
Hmm that one bisects to #18972 , opened a new issue at #19159 for that!
[-]Regression in upcoming mypy 1.16 - determining exhaustive match on an enum[/-][+][1.16 regression] determining exhaustive match on an enum with type members[/+]Allow enum members to have type objects as values
Allow enum members to have type objects as values (python#19160)
delfick commentedon May 28, 2025
Thanks for the fix @JukkaL ! I put that commit onto my local build of 1.16 and it worked great :)
Allow enum members to have type objects as values (#19160)
Allow enum members to have type objects as values (python#19160)