Re: [Python-Dev] Feature request: better support for "wrapper" objects
Recently, "Thomas Heller"
Here's an outline which could work in 2.2:
This sounds very good! There's only one thing you'll have to explain to me: how would this work from C? My types are all in C, not in Python, so I'd need to do the magic in C. Where do I find examples of using metatypes from C? I could then put all this wrapper stuff in a file WrapperObject.c and it would be reusable by any object that wanted this functionality.
Create a subtype of type, having a tp_convert slot:
typedef int (*convert_func)(PyTypeObject *, void **);
typedef struct { PyTypeObject type; convert_func tp_convert; } WrapperTypeType;
and use it as metaclass (metatype?) for your WindowObj:
class WindowObj(...): __metaclass__ = WrapperTypeType
Write a function to return a conversion function:
convert_func *get_converter(PyTypeObject *type) { if (WrapperTypeType_Check(type)) return ((WrapperTypeType *)type)->tp_convert; /* code to check additional types and return their converters */ .... }
and then
if (!PyArg_ParseTuple(args, "O&", get_converter(WinObj_Type), &Window))
How does this sound?
Thomas
--
- Jack Jansen
participants (3)
-
Jack Jansen
-
M.-A. Lemburg
-
Thomas Heller