[Python-Dev] What should changing/setting __getattr__ (and similars) after classdef time do ?
Samuele Pedroni
pedroni@inf.ethz.ch
Sun, 3 Jun 2001 01:46:42 +0200
Hi.
Thanks a lot for the answer, and sorry for the ill-formed question.
[Tim Peters]
> [Samuele Pedroni]
> > Is this a case that only the BDFL could know and pronounce on ...
> > or I'm missing somenthing ...
>
> The referenced URL
>
> http://www.python.org/doc/current/ref/customization.html
>
> appears irrelevant to me, so unsure what you're asking about. Perhaps
>
> http://www.python.org/doc/current/ref/attribute-access.html
>
> was intended? If so, the
Yes, pilot error with browser and copy&pasted, I intented the latter.
> these methods are cached in the class object at class
> definition time; therefore, they cannot be changed after
> the class definition is executed.
>
> there doesn't mean exactly what it says: it's trying to say that the
> __XXXattr__ methods *inherited from base classes* (if any) are cached in the
> class object at class definition time, so that changing them in the base
> classes later has no effect on the derived class. It should be clearer.
>
> A direct class setattr can still change them; indirect assignment via
> class.__dict__ is ineffective for the __dict__, __bases__, __name__,
> __getattr__, _setattr__ and __delattr__ class attributes (yes, you'll create
> a dict entry then, but class getattr doesn't look in the dict to get the
> value of these specific keys).
>
This matches what I understood reading CPython C code (yes I did that too
<wink>), and what the snippets was trying to point out. And I see the problem
with derived classes too.
> Didn't understand the program snippet.
Sorry it is not one snippet, but the 4 variants should be considered
indipendently.
>
> Much of this is due to hoary optimizations and I agree is ill-documented. I
> hope Guido's current rework of all this stuff will leave the endcases more
> explainable.
That will be a lot to work for porting it to jython <wink>.
In any case the manual is really not clear (euphemism <wink>) about this.
The point is that jython implements the letter of the manual, and even
extend the caching opt to some others __magic__ methods.
I wanted to know the intended behaviour in order to fix that in jython.
regards Samuele Pedroni.