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.

classification
Title: enum instance attribute access possible
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.6, Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: ethan.furman Nosy List: SilentGhost, barry, docs@python, eli.bendersky, ethan.furman, python-dev
Priority: normal Keywords: patch

Created on 2015-11-10 08:27 by SilentGhost, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
test_issue25594.diff SilentGhost, 2015-11-10 17:53 review
issue25594.stoneleaf.01.patch ethan.furman, 2015-11-13 18:18 review
issue25594.stoneleaf.03.patch ethan.furman, 2015-11-15 09:15 review
issue25594.stoneleaf.04.patch ethan.furman, 2015-11-18 04:42 review
Messages (8)
msg254436 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2015-11-10 08:27
In enum docs[0], there is a suggestion that the attribute access on members should raise an AttributeError:

>>> Color.red.blue
Traceback (most recent call last):
...
AttributeError: 'Color' object has no attribute 'blue'

which is demonstrably wrong in either 3.5 or 3.6. I presume that's a doc issue and I'd be glad to propose the patch as soon as someone more familiar with the module could confirm that.

[0] https://docs.python.org/3.6/library/enum.html#finer-points
msg254450 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2015-11-10 15:47
Nope, that would be a bug.
msg254460 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2015-11-10 17:53
Here is the test, it seems to have been 2545bfe0d273 that caused it (issue23486): test passes prior to it and fails on it (and I assume uniformly after).
msg254610 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2015-11-13 18:18
Thanks for tracking that down.

After more research I'm inclined to leave the code as it is and revamp the docs to clarify that while it may work, the results may not be what you want:

-- 8< -------------------
class Color(Enum):
    red = 1
    blue = 2
    name = 3

print(Color.name)         # Color.name
print(Color.name.blue)    # Color.blue
print(Color.blue.name)    # 'blue'  (not Color.name!)
-- 8< -------------------

Patch attached.
msg254685 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2015-11-15 11:19
No further comments re the latest patch.
msg254829 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2015-11-18 04:42
Changed the wording slightly to indicate that looking up members on other members is a bad idea.
msg255020 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-11-20 21:19
New changeset 276cf69b911e by Ethan Furman in branch '3.5':
Close issue25594: advise against accessing Enum members from other members
https://hg.python.org/cpython/rev/276cf69b911e
msg255022 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2015-11-20 21:35
Other changeset f4b495ceab17 in default branch.
History
Date User Action Args
2022-04-11 14:58:23adminsetgithub: 69780
2015-11-20 21:35:44ethan.furmansetmessages: + msg255022
2015-11-20 21:19:57python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg255020

resolution: fixed
stage: patch review -> resolved
2015-11-18 04:42:25ethan.furmansetfiles: + issue25594.stoneleaf.04.patch

messages: + msg254829
2015-11-15 11:19:39SilentGhostsetmessages: + msg254685
2015-11-15 09:15:44ethan.furmansetfiles: + issue25594.stoneleaf.03.patch
2015-11-13 18:18:24ethan.furmansetfiles: + issue25594.stoneleaf.01.patch

messages: + msg254610
stage: needs patch -> patch review
2015-11-10 20:09:27SilentGhostsettitle: enum docs outdated re attribute access -> enum instance attribute access possible
components: - Documentation
stage: test needed -> needs patch
2015-11-10 17:53:25SilentGhostsetfiles: + test_issue25594.diff
keywords: + patch
messages: + msg254460
2015-11-10 15:47:03ethan.furmansetassignee: docs@python -> ethan.furman
type: behavior
messages: + msg254450
stage: test needed
2015-11-10 08:27:47SilentGhostcreate