Question about accessing class-attributes.

Michele Simionato mis6+ at pitt.edu
Wed Apr 30 16:23:44 EDT 2003


Bjorn Pettersen wrote:
> > Michele Simionato wrote:
> > I must say, however, that len(S) is not *literally*
> > type(S).__len__(S):
> 
> Yes, that was one of my problems. Where did you find this rule? I can't
> find a real reference to it anywhere. For classic classes lookup is
> o.__class__.__dict__['attr'].__get__(o.__class__, o) for regular
> methods, which sort of looks like the above, but...

Never found any official reference except postings from Alex Martelli,
and
maybe I have read that in the Nutshell, too (Alex, correct me if I am
wrong!)
I do agree with you that the rule does not work in the case you pointed
out;
not sure if it is a bug or intended behaviour.

> [...]
> > I did not understood your point in the other thread, I didn't imagine
> > you where thinking about meta-metaclasses. As you see, there are
> > situations where they may be useful, i.e. in the customization of
> > metaclasses, but most people don't think at this level yet ;)
> 
> I wasn't (or at least wasn't trying to :-). They're facinating beasts
> though -- a semantic system with recursion in its axioms ;-)
> 
> -- bjorn

With meta-metaclasses you may implement type(S).__len__(S) but 
I see now that your point is more with len(S) that does not 
recognizes '__len__' methods provided indirectly via __getattr__ .
You can always do that

class Super(super):
    def __getattr__(self,somename):
        return somename
      
or even overrides __getattribute__ and implement an entirely
different version of super. Anyway, this does not solve your
problem. 

It seems to me more a problem of len that of super,
in the sense that len(x) is not *literally* type(x).__len__(x)
(idem for __getitem__ in the other thread; I would expect the
same for str and repr, I should check ...)

-- 
Michele Simionato - Dept. of Physics and Astronomy
210 Allen Hall Pittsburgh PA 15260 U.S.A.
Phone: 001-412-624-9041 Fax: 001-412-624-9163
Home-page: http://www.phyast.pitt.edu/~micheles/





More information about the Python-list mailing list