[Python-Dev] Object customization

Skip Montanaro skip@mojam.com (Skip Montanaro)
Fri, 14 Apr 2000 18:01:14 -0500 (CDT)


    Vladimir> I'll repeat myself:

    >>>> wink
    Vladimir> <wink object at 80c5f30>
    >>>> wink.fraction = 1e+-1
    >>>> wink.fraction.precision = 1e-+1
    >>>> wink.compute()
    Vladimir> 0.0

    Vladimir> Has anybody noticed that 'fraction' is a float I wanted to
    Vladimir> qualify with a 'precision' attribute?

Quick comment before I rush home...  There is a significant cost to be had
by adding attributes to numbers (ints at least).  They can no longer be
shared in the int cache.  I think the runtime size increase would be pretty
huge, as would the extra overhead in creating all those actual (small)
IntObjects instead of sharing a single copy.

On the other hand, functions are already pretty heavyweight objects and
occur much less frequently than numbers in common Python programs.  They
aren't shared (except for instance methods, which Barry's patch already
excludes), so there's no risk of stomping on attributes that are shared by
more than one function.

-- 
Skip Montanaro | http://www.mojam.com/
skip@mojam.com | http://www.musi-cal.com/