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 BreamoreBoy, Micah.Friesen, benjamin.peterson, daniel.urban, eric.araujo, eric.snow, ethan.furman, gangesmaster, pitrou, rhettinger, thomaslee
Date 2013-09-17.14:28:09
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1379428090.18.0.395073023219.issue1615@psf.upfronthosting.co.za>
In-reply-to
Content
Benjamin Peterson added the comment:
>
> I consider this to be a feature. Properties can raise AttributeError to defer to
> __getattr__.

Micah Friesen added the comment:
>
>I submit that this is not a feature - I can't imagine a real-world scenario [...]

No need to imagine.  The new Enum class uses this ability to support having both protected properties on enum members and enum members of the same name:

--> from enum import Enum
--> class Field(Enum):
-->     name = 1
...     age = 2
...     location = 3
... 
--> Field.name
<Field.name: 1>
--> Field.name.name
'name'

Enum's custom __getattr__ is located in the metaclass, however, not in the class.  For future reference, here is a short test script and it's output in 3.4.0a2+:
=====================================================================================
class WithOut:
    @property
    def huh(self):
        return self.not_here

class With:
    @property
    def huh(self):
        return self.not_here
    def __getattr__(self, name):
        print('looking up %s' % name)
        raise AttributeError('%s not in class %s' % (name, type(self)))

try:
    WithOut().huh
except AttributeError as exc:
    print(exc)

print()
try:
    With().huh
except AttributeError as exc:
    print(exc)

print()
import enum  # broken value property tries to access self.not_here
class TestEnum(enum.Enum):
    one = 1

print(TestEnum.one.value)
=====================================================================================
'WithOut' object has no attribute 'not_here'

looking up not_here
looking up huh
huh not in class <class '__main__.With'>

meta getattr with __new_member__
meta getattr with __new_member__
meta getattr with one
'TestEnum' object has no attribute 'not_here'
=====================================================================================
History
Date User Action Args
2013-09-17 14:28:10ethan.furmansetrecipients: + ethan.furman, rhettinger, pitrou, gangesmaster, thomaslee, benjamin.peterson, eric.araujo, daniel.urban, BreamoreBoy, eric.snow, Micah.Friesen
2013-09-17 14:28:10ethan.furmansetmessageid: <1379428090.18.0.395073023219.issue1615@psf.upfronthosting.co.za>
2013-09-17 14:28:10ethan.furmanlinkissue1615 messages
2013-09-17 14:28:09ethan.furmancreate