[Python-ideas] Specificity in AttributeError

Random832 random832 at fastmail.us
Sun Apr 28 05:03:20 CEST 2013


On 04/27/2013 12:44 AM, Devin Jeanpierre wrote:
> Code:
>       class A:
>          @property
>          def text(self):
>              return self.foo
>
> Behavior:
>      >>> hasattr(A(), 'text')
>      False
>
> Real Problem:
>      class B(object):
>          def __init__(self, x):
>              if hasattr(x, 'text'):
>                  x = x.text
>              self.x = x
>

What this is telling me:

     class A:
         def __hasattr__(self, name):
             if name == 'text': return True
             return super(A, self).__hasattr__(name)

This may or may not be something that @property, or some other 
decorator, ought to take care of.



More information about the Python-ideas mailing list