On 6/2/2021 7:59 PM, Ethan Furman wrote:
On 5/27/21 8:24 PM, Ethan Furman wrote:
> So, like the enum.unique decorator that can be used when duplicate
names should be an error,
> I'm adding a new decorator to verify that a Flag has no missing
aliased values that can be
> used when the programmer thinks it's appropriate... but I have no
idea what to call it.
>
> Any nominations?
Thank you everyone for your ideas! Instead of adding another
single-purpose decorator, I'm toying with the idea of adding a general
purpose decorator that accepts instructions. Something along the
lines of:
class EnumChecks(StrEnum):
"""
various conditions to check an enumeration for
"""
UNIQUE = "one name per value"
CONTINUOUS = "no skipped values"
DECOMPOSABLE_ALIASES = "flag aliases must have all bits named"
def verify(enumeration, *checks):
if UNIQUE in checks:
# ensure no duplicates
if CONTINUOUS in checks:
# ensure no missing values
if DECOMPOSABLE_ALIASES in checks:
# ensure all multi-flag aliases are composed of named flags
Thoughts?
Seems more forward-looking and extensible rather than a proliferation of
decorators. I like that.
And the EnumChecks provides a way to make a tradeoff between short names
(although DECOMPOSABLE_ALIASES isn't particularly short, it could be
made shorter given the explanations) and the explanations of them in the
text value.
However, for DECOMPOSABLE_ALIASES, not only is the name not short, the
explanation isn't particularly clear either, and it doesn't sound like
it would properly explain the case where you want to have a mask that is
larger than the number of currently used individual "flags" (which maybe
shouldn't be called "bits", but "flags"). That explanation confuses the
terminology between "masks" calling them "flags" and "flags" calling
them bits.
But maybe my understanding of what you originally meant the term "flag"
to mean in the Enum context is not clear... in any case, a terminology
should be used consistently, and the terminology should differentiate
between at least 3 cases:
1. single bit items (flag?)
2. multi-bit values that are not a superset of a group of related single
bit items (group?) e.g. PURPLE = RED | BLUE (not including GREEN)
3. multi-bit values that are intended as a mask, to include all related
single bit items as well as possibly reserving space for future,
yet-undefined, related single bit items. (mask?)
and maybe also
4. multi-bit fields containing a number, rather than a set of individual
bits (field?)
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at
https://mail.python.org/archives/list/python-dev@python.org/message/VPAMZXZFKJ5SVGUWSIV6DB5EBHXXLMCV/
Code of Conduct: http://python.org/psf/codeofconduct/