[Python-Dev] PEP 362: Signature objects

Guido van Rossum guido at python.org
Sat Sep 8 05:15:18 CEST 2007


On 9/7/07, Brett Cannon <brett at python.org> wrote:
> On 9/7/07, Jim Jewett <jimjjewett at gmail.com> wrote:
> > > A Signature object has the following structure attributes:
> >
> > > * name : str
> > >     Name of the function.  This is not fully qualified because
> > >     function objects for methods do not know the class they are
> > >     contained within.  This makes functions and methods
> > >     indistinguishable from one another when passed to decorators,
> > >     preventing proper creation of a fully qualified name.
> >
> > (1)  Would this change with the new static __class__ attribute used
> > for the new super?
>
> I don't know enough about the super implementation to know.  If you
> can figure out the class from the function object alone then sure,
> this can change.

I don't think it'll work -- the __class__ variable is only available
*within* the function, not when one is introspecting the function
object. Also, it is only available for functions that reference
'super' (or __class__ directly). As __class__ is passed into the
function call as a "cell" variable (like references to variables from
outer scopes), its mere presense slows down the call somewhat, hence
it is only present when used. (BTW, it is not an attribute.)

BTW there's a good reason why functions don't have easier access to
the class in which they are defined: functions can easily be moved or
shared between classes. The __class__ variable only records the class
inside which the function is defined lexically, if any.

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-Dev mailing list