[Python-3000] Method descriptors

Marcin ‘Qrczak’ Kowalczyk qrczak at knm.org.pl
Thu Dec 13 00:03:34 CET 2007


Dnia 12-12-2007, Śr o godzinie 15:10 +1300, Greg Ewing pisze:

> > > CFunction does not define descr_get - why?
> > 
> > I don't see why we should bother.
> 
> I put forward a possible reason recently -- so that
> Pyrex-defined functions could be used as methods
> without requiring any special trickery.

My case doesn't use the method wrapper type anymore. Adding the
appropriate descr_get to the generic wrapper of foreign objects,
distinguishing a foreign function type, works well. I'm still
surprised that CFunction differs from a Python function

I must say that I find the current set of various wrappers and
descriptors confusing: it doesn't seem to be described in one place;
a type has up to four names (a C API name, the name in repr of the type,
the name in repr of instances, and a name in types or builtin module);
the repr names have words separated by " ", "-" or "_" seemingly at
random; the sets of types available directly from C and from the types
module differ from each other, and also differ by Python versions;
and the types depend on technical details - for example the types of:
   MyClass.my_method
   str.upper
   str.__len__
are all different, even though they are all kinds of unbound methods.

Examples of name inconsistencies (with common "Type" suffixes stripped):

- a. CFunction 
  b. builtin_function_or_method
  c. built-in function
  d. BuiltinFunction = BuiltinMethod

- a. MemberDescr
  b. member_descriptor
  c. member
  d. MemberDescriptor

- a. MethodDescr
  b. method_descriptor
  c. method
  d. -

- a. Method
  b. method
  c. bound method
  d. Method

- a. - (wrapper, but not exported)
  b. method-wrapper
  c. method-wrapper
  d. -

- a. WrapperDescr
  b. wrapper_descriptor
  c. slot wrapper
  d. -

-- 
   __("<         Marcin Kowalczyk
   \__/       qrczak at knm.org.pl
    ^^     http://qrnik.knm.org.pl/~qrczak/



More information about the Python-3000 mailing list