Message22541
Logged In: YES
user_id=1038590
Without seeing the original code, I'm not convinced this is
a Python problem. This is due to the fact that inheriting
from builtin's and standard library objects defined in C
works fine.
For instance, inheriting dict's __len__ is shown here:
>>> class foo(dict): pass
...
>>> len(foo())
0
>>> foo.__len__
<slot wrapper '__len__' of 'dict' objects>
But grep shows the dict source makes no reference to
'__len__' directly:
[...@localhost src]$ grep -Hc "__len__" Objects/dictobject.c
Objects/dictobject.c:0
The way it works is that PyType_Ready generates the
appropriate __dict__ entries for all of the special methods
that are defined at the C level (i.e. have non-null pointers).
If you aren't invoking PyType_Ready before using your class,
then it won't work properly. (This invocation is usually
made in the C module's initialisation method). See the
"Extending and Embedding" docs for all the gory details. |
|
Date |
User |
Action |
Args |
2007-08-23 14:26:26 | admin | link | issue1034178 messages |
2007-08-23 14:26:26 | admin | create | |
|