The __unicode__ method in the C API, and other __-methods
Marcin 'Qrczak' Kowalczyk
qrczak at knm.org.pl
Fri Jun 11 06:53:18 EDT 2004
On Fri, 11 Jun 2004 07:04:55 +0200, Martin v. Löwis wrote:
>> and on the other hand the implementation
>> of tp_getattro of Kogut objects wrapped in Python has a special case,
>> only one special case, which checks for "__unicode__" and returns the
>> appropriate convert-to-Unicode bound method instead of forwarding the
>> attribute access to the original object.
>
> Why didn't you use Py_FindMethod for that?
Because I forward all other method calls to the wrapped object.
While I could check if Py_FindMethod raised AttributeError, clear the
error, and forward it in this case only - it's an overkill if there is
only a single method to intercept, and the majority of cases is forwarded.
This would change if I intercepted more methods, i.e. of I made __len__
etc. available as methods. I don't know if providing __len__ is a
requirement if sq_length is provided, and if so, if it's somehow possible
to avoid wrapping all those methods by hand.
For example if a method takes two arguments, its tp/nb/sq/mp slot takes
two arguments, while a MethodDef must take and unpack a two-element tuple,
as I understand, with ints passed as Python ints rather than C ints etc.
--
__("< Marcin Kowalczyk
\__/ qrczak at knm.org.pl
^^ http://qrnik.knm.org.pl/~qrczak/
More information about the Python-list
mailing list