[Python-Dev] PEP 362: Signature objects (original) (raw)

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