[Python-Dev] Object customization

Skip Montanaro skip@mojam.com (Skip Montanaro)
Sun, 16 Apr 2000 17:06:08 -0500 (CDT)


    Ken> We haven't even seen a satisfactory approach to referring to the
    Ken> function, itself, from within the function.  Maybe it's not even
    Ken> desirable to be able to do that - that's an interesting question.

I hereby propose that within a function the special name __ refer to the
function.  You could have

    def fact(n):
        if n <= 1: return 1
	return __(n-1) * n

You could also refer to function attributes through __ (presuming Barry's
proposed patch gets adopted):

    def pub(*args):
      if __.access == "private":
        do_private_stuff(*args)
      else:
        do_public_stuff(*args)

    ...

    if validate_permissions():
      pub.access = "private"
    else:
      pub.access = "public"

When in a bound method, __ should refer to the bound method, not the unbound
method, which is already accessible via the class name.

As far as lexical scopes are concerned, this won't change anything.  I think
it could be implemented by adding a reference to the function called __ in
the local vars of each function.

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