[Python-Dev] Object customization (was: Arbitrary attributes on funcs and methods)
Barry A. Warsaw
bwarsaw@cnri.reston.va.us
Fri, 14 Apr 2000 17:03:25 -0400 (EDT)
>>>>> "FL" == Fredrik Lundh <effbot@telia.com> writes:
FL> because people isn't likely to use __doc__ to store
FL> static variables?
Okay, let's really see how much we can abuse __doc__ today. I'm
surprised neither Zope nor SPARK are this evil. Why must I add the
extra level of obfuscating indirection?
Or are we talking about making __doc__ read-only in 1.6, or
restricting it to strings only?
-Barry
-------------------- snip snip --------------------
import sys
print sys.version
def decorate(func):
class D:
pass
doc = func.__doc__
func.__doc__ = D()
func.__doc__.__doc__ = doc
def eff():
"eff"
print "eff", eff.__doc__.__doc__
decorate(eff)
def bot():
"bot"
print "bot", bot.__doc__.__doc__
decorate(bot)
eff.__doc__.publish = 1
bot.__doc__.publish = 0
eff()
bot()
eff, bot = bot, eff
eff()
bot()
for f in (eff, bot):
print 'Can I publish %s? ... %s' % (f.__name__,
f.__doc__.publish and 'yes' or 'no')
-------------------- snip snip --------------------
% python /tmp/scary.py
1.5.2 (#7, Apr 16 1999, 18:24:22) [GCC 2.8.1]
eff eff
bot bot
bot eff
eff bot
Can I publish bot? ... no
Can I publish eff? ... yes