If someone reads that post:
On 11 Dez., 18:52, Simon King <
simon.k...@uni-jena.de> wrote:
> ...
> If there is no way to circumvent the lookup:
> Do you think it is reasonable to change Element.__getattr__ so that it
> immediately raises an AttributeError if the requested attribute name
> starts with two underscores, but does not end with an underscore?
> IIRC, those attributes are supposed to be private (and are subject to
> name mangling), so that it may make sense to exclude them from lookup.
Indeed: If one does what I suggested then all doctests still pass.
> A related question:
> The __repr__ method of Sage objects does in fact
> if hasattr(self,'__custom_name'):
> return self.__custom_name
>
> Wouldn't it be slightly faster to do
> try:
> return self.__custom_name
> except AttributeError:
> pass
It is indeed a lot faster. I changed this and other occurences as
well.
The patch is at ticket #10467, which is ready for review! It provides
two examples (one of them a real computation) where the computation
time drops by almost 1/2 due to the improved attribute lookup.
Cheers,
Simon