[issue19011] Enum should have a __getattr__ that makes all the instances available from an instance
Roundup Robot added the comment: New changeset 47fb6b078b5f by Ethan Furman in branch 'default': Close #19011: Add documentation on some of the non-standard Enum behavior. http://hg.python.org/cpython/rev/47fb6b078b5f -- nosy: +python-dev resolution: - fixed stage: patch review - committed/rejected status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19011 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19011] Enum should have a __getattr__ that makes all the instances available from an instance
Ethan Furman added the comment: As discussed on PyDev[1], Enum members are bonafide class attributes, as in they show on the class, not on the instances. Documentation patch attached. [1] https://mail.python.org/pipermail/python-dev/2013-September/128874.html -- stage: - patch review type: - behavior Added file: http://bugs.python.org/file31863/issue19011.stoneleaf.01.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19011 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19011] Enum should have a __getattr__ that makes all the instances available from an instance
Ethan Furman added the comment: Posted a message on PyDev, but unless I get feedback saying it's a bad idea, or I find some implementation issue, I'll go ahead and make the change. So either a doc patch or an enum patch will be in alpha3. :) -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19011 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19011] Enum should have a __getattr__ that makes all the instances available from an instance
New submission from Chris Lambacher: The use case for this is that when you are in a template and you want to use the Enum instances in a conditional, then you need to pass the Enum class to the template or start using someenumvariable.__class__.someenumvalue. Instead it would be useful to be able to do someenumvariable.someenumvalue. Implimenting as __getattr__ on enum class allows real attributes to take precedence and also allows for overriding of behaviour in child classes. -- components: Library (Lib) files: getattr_for_enum_class.patch keywords: patch messages: 197611 nosy: lambacck priority: normal severity: normal status: open title: Enum should have a __getattr__ that makes all the instances available from an instance versions: Python 3.4 Added file: http://bugs.python.org/file31745/getattr_for_enum_class.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19011 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19011] Enum should have a __getattr__ that makes all the instances available from an instance
Ethan Furman added the comment: -- class Test: ... this = 'that' ... these = 'those' ... -- Test.this 'that' -- Test.this.these Traceback (most recent call last): File stdin, line 1, in module AttributeError: 'str' object has no attribute 'these' This is not normal Python behavior, nor does it seem to be behavior intrinsic to enumerations. It also adds an Alice-in-Wonderland quality to Enums: -- red = Color.red -- red.blue.blue.red.green.blue Color.blue: 3 We're going to have to live without this particular feature. -- assignee: - ethan.furman nosy: +barry, eli.bendersky, ethan.furman resolution: - rejected status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19011 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19011] Enum should have a __getattr__ that makes all the instances available from an instance
Ethan Furman added the comment: My apologies, you are correct. I am still against this for the Alice reason, but lets see what the others think. -- resolution: rejected - status: closed - open ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19011 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19011] Enum should have a __getattr__ that makes all the instances available from an instance
Chris Lambacher added the comment: You are not comparing the same thing. Normally when there is a class parameter, those are available from instances of the class. class Test: ...pass ... Test.this = Test() Test.that = Test() Test.this.that __main__.Test instance at 0x7ff681bd3560 isinstance(Test.this, Test) True from enum import IntEnum class Color(IntEnum): ... red = 1 ... blue = 2 ... green = 3 ... isinstance(Color.red, Color) True -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19011 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19011] Enum should have a __getattr__ that makes all the instances available from an instance
Chris Lambacher added the comment: For what it's worth, I was confused by the inability to access the class members from the instance for like 3 or 4 weeks until I realized that the instances were not actually on the class and the implications of that for class attribute access. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19011 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com