[Python-Dev] Object customization (was: Arbitrary attributes on funcs and methods)

Gordon McMillan gmcm@hypernet.com
Fri, 14 Apr 2000 15:36:53 -0400


Fredrik Lundh wrote:

> > To belabor the obvious (existing Python allows obsfuction), I 
> > present:
> > 
> > class eff:
> >   "eff"
> >   def __call__(self):
> >     print "eff", eff.__doc__
> >     
> > class bot:
> >   "bot"
> >   def __call__(self):
> >     print "bot", bot.__doc__
> >     
> > e = eff()
> > b = bot()
> > e()
> > b()
> > 
> > eff, bot = bot, eff
> > e = eff()
> > b = bot()
> > e()
> > b() 
> > 
> > There's nothing new here. Why does allowing the ability to 
> > obsfucate suddenly warrant a -1?
> 
> since when did Python grow full lexical scoping?

I know that's not Swedish, but I haven't the foggiest what 
you're getting at. Where did lexical scoping enter?
 
> does anyone that has learned about the LGB rule expect
> the above to work?

You're the one who did "eff, bot = bot, eff". The only intent I 
can infer is obsfuction. The above works the same as yours, 
for whatever your definition of "work".
 
> in contrast, my example used a name which appears to be
> defined in the same scope as the other names introduced
> on the same line of source code -- but isn't.
> 
>     def foo(x):
>         foo.x = x

I guess I'm missing something.

-------snip------------
def eff():
    "eff"
    print "eff", eff.__doc__

def bot():
    "bot"
    print "bot", bot.__doc__

eff()
bot()

eff, bot = bot, eff

eff()
bot()
-----------end-----------

I guess we're not talking about the same example.

 
> here, "foo" doesn't refer to the same namespace as the
> argument "x", but to instead whatever happens to be in
> an entirely different namespace at the time the function
> is executed.
> 
> in other words, this feature cannot really be used to store
> statics -- it only looks that way...

Again, I'm mystified. After "eff, bot = bot, eff", I don't see why 
'bot() == "eff bot"' is a wrong result.

Put it another way: are you reporting a bug in 1.5.2? If it's a 
bug, why is my example not a bug? If it's not a bug, why 
would the existence of other attributes besides __doc__ be a 
problem?

- Gordon