[Python-Dev] Re: name for new Enum decorator

2021-06-07 Thread Andrei Kulakov
On Mon, Jun 7, 2021 at 1:36 PM Ethan Furman  wrote:

> On 6/6/21 9:14 AM, Irit Katriel via Python-Dev wrote:
>  > On 6 Jun 2021, at 16:58, Andrei Kulakov wrote:
>
>  >> In Math / CompSci there is a definition that almost exactly matches
> this: Exact Cover -
>  >> https://en.wikipedia.org/wiki/Exact_cover
>  >>
>  >> The difference is that, IIRC, solving the problem is finding and
> removing all subsets that are unneeded to create an
>  >> exact cover, so it's kind of arriving at it from a different
> direction, but 'exact cover' definition itself is a good
>  >> match.
>  >
>  > I’m not sure it’s a quite the same - it doesn’t require that the sets
> in the cover have cardinality 1, which I think
>  > Ethan does.
>
> Well, I'm not sure what "cardinality 1" means, so I don't know if I do or
> not.  :)
>
>
> It means each bit flag has only one bit set. In the 'exact cover'
definition, that's not a requirement (if it were, it would
make the problem too trivial to solve).

I also want to mention that 'exact cover' seems a very direct, easy to
remember name also for users who are not
familiar with the Math definition..

 -andrei
___
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/MZTPKDWUE47ZXJKN6BISFCJ5RZ5XSOS5/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: name for new Enum decorator

2021-06-06 Thread Andrei Kulakov
On Thu, May 27, 2021 at 11:31 PM 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?
>
> --
> ~Ethan~
>
>
In Math / CompSci there is a definition that almost exactly matches this:
Exact Cover - https://en.wikipedia.org/wiki/Exact_cover

The difference is that, IIRC, solving the problem is finding and removing
all subsets that are unneeded to create an exact cover, so it's kind of
arriving at it from a different direction, but 'exact cover' definition
itself is a good match.

-andrei
___
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/ZWAI6Q5HI3UBMXGGUWZO6TZGKUCEC7ND/
Code of Conduct: http://python.org/psf/codeofconduct/