On Sat, Dec 12, 2020 at 07:01:55PM -0800, Ethan Furman wrote:

> That's invalid.  Duplicates allowed means:
> 
> > ```
> > class K( NamedValue):
> >      A = 1
> >      B = 1
> > ```
> B is not an alias for A.  Presumably one has the same number with different 
> meaning.  If that were an Enum:
> 
> ```
> >>> K.B
> K.A

Ah! Talking about Boy Looks, I had never noticed that behaviour before. 
(But then I don't regularly use duplicate Enum values.)

What is the reason for that behaviour in Enums?


> >I'm not following this either. Can you give an example of something that 
> >doesn't work with Enum (and shouldn't work) but should work with 
> >NamedValues?
> 
> Class MyEnum(Enum):
>     ONE = 1
>     TWO = 2
> 
> MyEnum.ONE + 3
> # TypeError
> 
> Class MyValue(NamedValue):
>     ONE = 1
>     TWO = 2
> 
> MyValue.TWO + 3
> 5

Isn't this the solution to that?

>>> class MyValue(int, Enum):
...     ONE = 1
...     TWO = 2
... 
>>> MyValue.TWO + 3
5


-- 
Steve
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/QU2P6V6U7BD2NH7P2BCIWWQBKE4UE7ST/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to