This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ethan.furman
Recipients barry, eli.bendersky, ethan.furman, ezio.melotti, python-dev, r.david.murray, rhettinger, serhiy.storchaka, veky
Date 2016-09-08.18:05:58
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1473357958.39.0.97087103741.issue23591@psf.upfronthosting.co.za>
In-reply-to
Content
Just so we're clear:  I'm going to go with "auto()" and (mostly) use Python's standard routines (with only a little bit of metaclass magic).

Vedran opined:
> Since you like examples, what do you say about

I love examples!  Examples are like pictures, which are worth a thousand words.  ;)

>    class MyEnum(Enum):
>        red = some_function()
>        blue = red
>
> Now, is MyEnum.blue the same as MyEnum.red (watch: not "equal", but
> "same")?

Yes.

> Well, it depends on what some_function returns, right?

Nope.

> If it returns _auto_, they are not the same, but in all the other
> cases, blue is just an alias for red. So object identity depends on
> some value that could be external to the class. To me that's
> obviously unacceptable.

That would be unacceptable.  However, it would also be impossible*, because "_auto_" would be injected into the class namespace during "__prepare__()" and be unavailable for an external function to return.

* as impossible as anything is in Python -- so really, really difficult

> But even "the namespace class body is executed in" _should_ be a Python
> namespace, with all its rules.

One of those rules is:  the namespace is dict-like.

Which means it has methods such as __getitem__, __setitem__, etc., which means those methods can implement whatever is needed to give the namespace the desired semantics (within Python syntax).

Which, to some extent, is what will be used to transform an instance of "auto" into an appropriate integer.  In other words:

>>> class Color(Enum):
...     red = auto()
...     print(red)
...
1
>>> Color.red
<Color.red: 1>
History
Date User Action Args
2016-09-08 18:05:58ethan.furmansetrecipients: + ethan.furman, barry, rhettinger, ezio.melotti, r.david.murray, eli.bendersky, python-dev, serhiy.storchaka, veky
2016-09-08 18:05:58ethan.furmansetmessageid: <1473357958.39.0.97087103741.issue23591@psf.upfronthosting.co.za>
2016-09-08 18:05:58ethan.furmanlinkissue23591 messages
2016-09-08 18:05:58ethan.furmancreate