[Python-ideas] Re: a new data type: NamedValue -- similar to Enum

2020-12-13 Thread Ethan Furman
On 12/12/20 7:25 PM, Steven D'Aprano wrote: > On Sat, Dec 12, 2020 at 06:00:17PM -0800, Ethan Furman wrote: >> Enum is great! Okay, okay, my opinion might be biased. ;) >> >> There is one area where Enum is not great -- for a bunch of unrelated >> values. > > I don't know how to interpret

[Python-ideas] Re: a new data type: NamedValue -- similar to Enum

2020-12-13 Thread Steven D'Aprano
On Sun, Dec 13, 2020 at 12:34:27AM -0800, Ethan Furman wrote: [me] > class MyValue(int, Enum): > >... ONE = 1 > >... TWO = 2 > >... > MyValue.TWO + 3 > >5 > > It certainly can be abused for that, but the intended purpose of IntEnum is > not to support math operations, but rather

[Python-ideas] Re: a new data type: NamedValue -- similar to Enum

2020-12-13 Thread Ethan Furman
On 12/12/20 7:52 PM, Steven D'Aprano wrote: 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.

[Python-ideas] Re: a new data type: NamedValue -- similar to Enum

2020-12-12 Thread Steven D'Aprano
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: >

[Python-ideas] Re: a new data type: NamedValue -- similar to Enum

2020-12-12 Thread Steven D'Aprano
On Sat, Dec 12, 2020 at 06:00:17PM -0800, Ethan Furman wrote: > Enum is great! Okay, okay, my opinion might be biased. ;) > > There is one area where Enum is not great -- for a bunch of unrelated > values. I don't know how to interpret that. Surely *in practice* enums are always going to be

[Python-ideas] Re: a new data type: NamedValue -- similar to Enum

2020-12-12 Thread Ethan Furman
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.

[Python-ideas] Re: a new data type: NamedValue -- similar to Enum

2020-12-12 Thread Guido van Rossum
Okay, I'll bite. On Sat, Dec 12, 2020 at 6:00 PM Ethan Furman wrote: > unlike Enum, duplicates are allowed > What does this even mean? ``` class K( NamedValues): A = 1 A = 2 ``` Why would I want that? > unlike Enum, new values can be added after class definition > Sure, that points