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
A need for labels in grouped values became apparent in #150. Syntax like this would be nice:
classPOSTSTATUS(LabeledEnum):
DRAFT= (0, __("Draft")) # Being writtenPENDING= (1, __("Pending")) # Pending email verificationCONFIRMED= (2, __("Confirmed")) # Post is now live on siteREVIEWED= (3, __("Reviewed")) # Reviewed and cleared for push channelsUNPUBLISHED= {DRAFT, PENDING}, __("Unpublished")
LISTED= ({CONFIRMED, REVIEWED}, __("Listed"))
From an implementation standpoint, the two grouped entries (identical in effect thanks to Python's automatic list packing) will show up as a tuple, but with the first element being a set instead of a non-set (integer, string, etc). In this case the metaclass needs to parse the set for inner values. Relevant code:
The labels dictionary can't have a set as the key. The set must be converted into a frozenset. However, frozensets aren't instances of a set (as per isinstance) and so there could be downstream breakage. If we use a frozenset (or a tuple) only for the key, without changing the actual value, it breaks dictionary access to the label (for example, POSTSTATUS[POSTSTATUS.UNPUBLISHED]).
Dictionary enumeration is meant to provide a list of keys that are valid values for setting a status flag. If we provide grouped values in this enumeration, it breaks another downstream use case.
Perhaps grouped value labels should be stored separately, and lookup should happen as a fallback when __getitem__ notices the key is a set or frozenset.
Given the increased complexity to LabeledEnum's implementation, this ticket should be parked until #150 establishes a clear need for group labels.
Closing this as #150 did not find a use case for labels in groups. Our use case for labels remains the UI display of the current primary state. Grouped states are tested against, but not displayed (so far). Will re-open if this changes.
A need for labels in grouped values became apparent in #150. Syntax like this would be nice:
From an implementation standpoint, the two grouped entries (identical in effect thanks to Python's automatic list packing) will show up as a tuple, but with the first element being a set instead of a non-set (integer, string, etc). In this case the metaclass needs to parse the set for inner values. Relevant code:
coaster/coaster/utils/classes.py
Lines 23 to 33 in b03b28a
The text was updated successfully, but these errors were encountered: