Re: Behavior of auto in Enum and Flag.

2017-04-03 Thread Oren Ben-Kiki
On Mon, Apr 3, 2017 at 7:43 PM, Chris Angelico wrote: > Here's a counter-example that supports the current behaviour: > > >>> from enum import IntFlag, auto > >>> class Spam(IntFlag): > ... FOO = auto() > ... BAR = auto() > ... FOOBAR = FOO | BAR > ... SPAM = auto() > ... HAM

Re: Behavior of auto in Enum and Flag.

2017-04-03 Thread Chris Angelico
On Tue, Apr 4, 2017 at 2:29 AM, Ethan Furman wrote: > It this point I do not. If you can give us an example Enum and why it's > necessary to be built like that I might be swayed -- although the odds are > good that the change will go into aenum instead (it's already a mess with > the 2.7 compatib

Re: Behavior of auto in Enum and Flag.

2017-04-03 Thread Ethan Furman
On 04/03/2017 01:53 AM, Oren Ben-Kiki wrote: On Mon, Apr 3, 2017 at 11:03 AM, Ethan Furman wrote: Python code is executed top-down. First FOO, then BAR, then BAZ. It is not saved up and executed later in random order. Or, put another way, the value was appropriate when it was chosen -- it

Re: Behavior of auto in Enum and Flag.

2017-04-03 Thread Oren Ben-Kiki
On Mon, Apr 3, 2017 at 11:03 AM, Ethan Furman wrote: > Python code is executed top-down. First FOO, then BAR, then BAZ. It is > not saved up and executed later in random order. Or, put another way, the > value was appropriate when it was chosen -- it is not the fault of auto() > that the user

Re: Behavior of auto in Enum and Flag.

2017-04-03 Thread Ethan Furman
On 04/02/2017 09:49 PM, Oren Ben-Kiki wrote: The current behavior of `auto` is to pick a value which is one plus the previous value. Starting with 1 if no previous value exists. It would probably be better if `auto` instead picked a value that is not used by any named member (either the mini

Re: Behavior of auto in Enum and Flag.

2017-04-02 Thread Oren Ben-Kiki
While "the current behaviour is compliant with what the docs say" is true, saying "as such, I would be disinclined to change the code" misses the point. The current documentation allows for multiple behaviors. The current implementation has an chosen to add an arbitrary undocumented restriction on

Re: Behavior of auto in Enum and Flag.

2017-04-02 Thread Chris Angelico
On Mon, Apr 3, 2017 at 2:49 PM, Oren Ben-Kiki wrote: > "If the exact value is unimportant you may use auto instances and an > appropriate value will be chosen for you." > > Choosing a value that conflicts with BAZ in above cases doesn't seem > "appropriate" for a value that is "unimportant". > > T

Behavior of auto in Enum and Flag.

2017-04-02 Thread Oren Ben-Kiki
The current behavior of `auto` is to pick a value which is one plus the previous value. It would probably be better if `auto` instead picked a value that is not used by any named member (either the minimal unused value, or the minimal higher than the previous value). That is, in this simple case: