On 12/12/20 6:40 PM, Guido van Rossum wrote:

unlike Enum, duplicates are allowed


What does this even mean?
```
class K( NamedValue):
     A = 1
     A = 2
```

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

unlike Enum, new values can be added after class definition

Sure, that points to maybe a subclass of Enum?

Not really -- adding a new member to an Enum is a royal pain.

unlike Enum, a NamedValue can always be used as-is, even if no data type has 
been mixed in -- in other words, there is
no functional difference between MyIntConstants(int, NamedValue) and 
MyConstants(NamedValue).

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

Finally, why the plural in the name, where Enum and friends all have singular 
names?

Because I constantly forget, and have to go back to remove the plural 's'.

By the way, the use of classes is not strictly required -- we could get everything except for immutable class access by using mostly the same method as sre_parse._NamedIntConstant if we want a /slightly/ lighter weight structure -- which is to say the NamedValueMeta is no where near as complicated as EnumMeta.

--
~Ethan~
_______________________________________________
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/3MZ5KL5EP6JJ3M5P7VTMCPFQHSRM67MO/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to