Why doesnt __getattr__ with decorator dont call __get_method in decorator
glomde
tbrkic at yahoo.com
Thu Mar 29 10:48:36 EDT 2007
> To get python to run the __get__ method I think you have to call
> __getattr__ explicitly:
> a.__getattr__('test')
>
> If you do:
> a.test
> python follows a different routine: it checks for the existence of the
> attribute, then check if there is a __getattr__ attribute. Now the
> speculative bit: then I conjecture that python assumes that
> __getattr__ is a function with two arguments and directly passes them
> on to it. Indeed
>
> type(a).__dict__['__getattr__'](a, 'test')
>
> seems to produce the same errors as a.test, whether the instance
> attribute is set or not.
> And this explain why there are too many arguments (error message
> above).
>
> --
> Arnaud
So is this a python bug? I assumed it was seen as function but dont
understand why it is like this. But interesting that if you call
__getattr__ explicitly it works.
Intuitevely I would assumet that the same route should be followed
in both case.
Maybe it is because __getattr__ is called only when you have an
exception.
/T
More information about the Python-list
mailing list