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
Now that RFC 8 and RFC 9 are merged, we have two extension points (EnumMeta.__call__ and EnumMeta.const) that can be used to inject a wrapper class checking that the enum-shaped value is used accordingly.
For enums that do not inherit from int, the result of Value.cast(E.X) should not be a Value (as it currently is), and the only operations that can be performed directly should be comparisons (==, !=).
For flags that do not inherit from int, the result of Value.cast(E.X) should not be a Value (as it currently is), and the only operations that can be performed directly should be comparisons and bitflag set operations (==, !=, |, &, ^).
(This is essentially the same level of type safety as afforded by the Python enum module.)
For enums and flags that do inherit from int, the result should be a Value or at least proxying a Value (we don't currently have such a thing but maybe we should? for cases where no semantic change is desired besides some linting). This seems a lot more difficult to support. I think we don't really have to; it's the former case that worries me.
I'm putting this in the 0.4 milestone because for making Value.cast(E.X) return something other than a Value where E is a builtin Enum the ship has long sailed, but we could still return amaranth.lib.enum.EnumView or something where E is an amaranth.lib.enum.Enum since that hasn't appeared in a release yet. It becomes less of a technical drop-in replacement for the builtin Enum then (although arguably more of a conceptual drop-in replacement, since we're replicating builtin behavior), but it's probably OK since the workaround (import enum as py_enum) is trivial.
Someone needs to prototype this before writing an RFC.
The text was updated successfully, but these errors were encountered:
Now that RFC 8 and RFC 9 are merged, we have two extension points (
EnumMeta.__call__
andEnumMeta.const
) that can be used to inject a wrapper class checking that the enum-shaped value is used accordingly.int
, the result ofValue.cast(E.X)
should not be aValue
(as it currently is), and the only operations that can be performed directly should be comparisons (==
,!=
).int
, the result ofValue.cast(E.X)
should not be aValue
(as it currently is), and the only operations that can be performed directly should be comparisons and bitflag set operations (==
,!=
,|
,&
,^
).(This is essentially the same level of type safety as afforded by the Python
enum
module.)int
, the result should be aValue
or at least proxying aValue
(we don't currently have such a thing but maybe we should? for cases where no semantic change is desired besides some linting). This seems a lot more difficult to support. I think we don't really have to; it's the former case that worries me.I'm putting this in the 0.4 milestone because for making
Value.cast(E.X)
return something other than aValue
whereE
is a builtinEnum
the ship has long sailed, but we could still returnamaranth.lib.enum.EnumView
or something whereE
is anamaranth.lib.enum.Enum
since that hasn't appeared in a release yet. It becomes less of a technical drop-in replacement for the builtinEnum
then (although arguably more of a conceptual drop-in replacement, since we're replicating builtin behavior), but it's probably OK since the workaround (import enum as py_enum
) is trivial.Someone needs to prototype this before writing an RFC.
The text was updated successfully, but these errors were encountered: