Re: name for new Enum decorator
On 5/28/21 5:23 AM, Ethan Furman wrote: Greetings! The Flag type in the enum module has had some improvements, but I find it necessary to move one of those improvements into a decorator instead, and I'm having a hard time thinking up a name. What is the behavior? Well, a name in a flag type can be either canonical (it represents one thing), or aliased (it represents two or more things). To use Color as an example: class Color(Flag): RED = 1 # 0001 GREEN = 2 # 0010 BLUE = 4 # 0100 PURPLE = RED | BLUE # 0101 WHITE = RED | GREEN | BLUE # 0111 The flags RED, GREEN, and BLUE are all canonical, while PURPLE and WHITE are aliases for certain flag combinations. But what if we have something like: class Color(Flag): RED = 1 # 0001 BLUE = 4 # 0100 WHITE = 7 # 0111 As you see, WHITE is an "alias" for a value that does not exist in the Flag (0010, or 2). That seems like it's probably an error. But what about this? class FlagWithMasks(IntFlag): DEFAULT = 0x0 FIRST_MASK = 0xF FIRST_ROUND = 0x0 FIRST_CEIL = 0x1 FIRST_TRUNC = 0x2 SECOND_MASK = 0xF0 SECOND_RECALC = 0x00 SECOND_NO_RECALC = 0x10 THIRD_MASK = 0xF00 THIRD_DISCARD = 0x000 THIRD_KEEP = 0x100 Here we have three flags (FIRST_MASK, SECOND_MASK, THIRD_MASK) that are aliasing values that don't exist, but it seems intentional and not an error. 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? Why don't you just use the colour names from rgb.txt and their values? That's plain, simple and pretty standard. -- https://mail.python.org/mailman/listinfo/python-list
Re: name for new Enum decorator
On 2021-05-28 04:23, Ethan Furman wrote: Greetings! The Flag type in the enum module has had some improvements, but I find it necessary to move one of those improvements into a decorator instead, and I'm having a hard time thinking up a name. [snip] 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? "checked"? -- https://mail.python.org/mailman/listinfo/python-list
Re: name for new Enum decorator
On 2021-05-27 at 20:23:29 -0700, Regarding "name for new Enum decorator," Ethan Furman wrote: > Greetings! > > The Flag type in the enum module has had some improvements, but I find it > necessary to move one of those improvements into a decorator instead, and > I'm having a hard time thinking up a name. > > What is the behavior? Well, a name in a flag type can be either canonical > (it represents one thing), or aliased (it represents two or more things). > To use Color as an example: > > class Color(Flag): > RED = 1# 0001 > GREEN = 2 # 0010 > BLUE = 4 # 0100 > PURPLE = RED | BLUE# 0101 > WHITE = RED | GREEN | BLUE # 0111 > > The flags RED, GREEN, and BLUE are all canonical, while PURPLE and WHITE are > aliases for certain flag combinations. But what if we have something like: > > class Color(Flag): > RED = 1# 0001 > BLUE = 4 # 0100 > WHITE = 7 # 0111 > > As you see, WHITE is an "alias" for a value that does not exist in the Flag > (0010, or 2). That seems like it's probably an error. But what about this? > > class FlagWithMasks(IntFlag): > DEFAULT = 0x0 > > FIRST_MASK = 0xF > FIRST_ROUND = 0x0 > FIRST_CEIL = 0x1 > FIRST_TRUNC = 0x2 > > SECOND_MASK = 0xF0 > SECOND_RECALC = 0x00 > SECOND_NO_RECALC = 0x10 > > THIRD_MASK = 0xF00 > THIRD_DISCARD = 0x000 > THIRD_KEEP = 0x100 > > Here we have three flags (FIRST_MASK, SECOND_MASK, THIRD_MASK) that are > aliasing values that don't exist, but it seems intentional and not an error. > > 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? Exhaustive? I see two qualitatively different kinds of enums: those that can/should be "or"ed together (e.g., RED, GREEN) and those that cannot (e.g., FIRST_ROUND, FIRST_CEIL, and FIRST_TRUNC). The idea of a "missing" value doesn't seem to apply to the second type (because defining FIRST_TRUNC as FIRST_ROUND | FIRST_CEIL is nonsensical). I don't quite know what that may or may not suggest as far as names go, but it may give someone else an idea. -- https://mail.python.org/mailman/listinfo/python-list
name for new Enum decorator
Greetings! The Flag type in the enum module has had some improvements, but I find it necessary to move one of those improvements into a decorator instead, and I'm having a hard time thinking up a name. What is the behavior? Well, a name in a flag type can be either canonical (it represents one thing), or aliased (it represents two or more things). To use Color as an example: class Color(Flag): RED = 1# 0001 GREEN = 2 # 0010 BLUE = 4 # 0100 PURPLE = RED | BLUE# 0101 WHITE = RED | GREEN | BLUE # 0111 The flags RED, GREEN, and BLUE are all canonical, while PURPLE and WHITE are aliases for certain flag combinations. But what if we have something like: class Color(Flag): RED = 1# 0001 BLUE = 4 # 0100 WHITE = 7 # 0111 As you see, WHITE is an "alias" for a value that does not exist in the Flag (0010, or 2). That seems like it's probably an error. But what about this? class FlagWithMasks(IntFlag): DEFAULT = 0x0 FIRST_MASK = 0xF FIRST_ROUND = 0x0 FIRST_CEIL = 0x1 FIRST_TRUNC = 0x2 SECOND_MASK = 0xF0 SECOND_RECALC = 0x00 SECOND_NO_RECALC = 0x10 THIRD_MASK = 0xF00 THIRD_DISCARD = 0x000 THIRD_KEEP = 0x100 Here we have three flags (FIRST_MASK, SECOND_MASK, THIRD_MASK) that are aliasing values that don't exist, but it seems intentional and not an error. 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? -- ~Ethan~ -- https://mail.python.org/mailman/listinfo/python-list