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
Support Union of Enum and/or Literal in annotations for with_annotated decorator #1686
Support Union of Enum and/or Literal in annotations for with_annotated decorator. Especially unions for different Enums seams to be desirable to reduce code duplication.
I will add support for this use case. For now, I will allow only a mix of Enum and Literal, since they are "constant-like". For most other options, I think it will be very ambiguous to tell what it should resolve to.
After some thinking, I am not sure if the use case actually makes sense, or if it is better to be done via a combination of the existing construct.
EnumA | EnumB: I cannot think of a case where you would want to do this. If A and B are relevant inputs, you will likely put them into a single enum.
EnumA | Literal["auto"]: this use case makes sense, since you might want an option that is not part of the enum, but you will still want a value. In this use case, would using the _missing_ method to set a default be a better idea?
EnumA | Literal["autoA", ...]: this basically falls back to using _missing_ again, since likely any of the literal options will go to
I will add documentation and update the code path. Since right now, it will only trigger a hard error. I will add a new option that takes in an unknown member and let it trigger the _missing_ on the enum.
Activity
KelvinChung2000 commentedon Jun 10, 2026
I will add support for this use case. For now, I will allow only a mix of
EnumandLiteral, since they are "constant-like". For most other options, I think it will be very ambiguous to tell what it should resolve to.KelvinChung2000 commentedon Jun 15, 2026
After some thinking, I am not sure if the use case actually makes sense, or if it is better to be done via a combination of the existing construct.
EnumA | EnumB: I cannot think of a case where you would want to do this. If A and B are relevant inputs, you will likely put them into a single enum.EnumA | Literal["auto"]: this use case makes sense, since you might want an option that is not part of the enum, but you will still want a value. In this use case, would using the_missing_method to set a default be a better idea?EnumA | Literal["autoA", ...]: this basically falls back to using_missing_again, since likely any of the literal options will go toI will add documentation and update the code path. Since right now, it will only trigger a hard error. I will add a new option that takes in an unknown member and let it trigger the
_missing_on the enum.neoniobium commentedon Jun 15, 2026
I use
EnumA,EnumBas well asEnumA | EnumBas possible arguments for different functions.