[Python-Dev] C-level duck typing
Dag Sverre Seljebotn
d.s.seljebotn at astro.uio.no
Wed May 16 10:25:21 CEST 2012
On 05/16/2012 10:11 AM, Nick Coghlan wrote:
> Use PyObject_HasAttr, just as people use hasattr() for ducktyping in Python.
In the Cython wrap-function-pointers case we really want performance
comparable to C, so we couldn't do the whole thing.
But I guess we could intern some char* (somehow), pass that to
tp_getattr, and then cast the returned PyObject* (which would not be a
PyObject*) to a custom struct. As long as the interned strings can never
be reached from Python that's almost safe. It's still slight abuse of
tp_getattr.
As I said, if we didn't worry about performance we'd just retrieve
capsules through attributes.
Dag
>
> If you want something more structured, use Abstract Base Classes,
> that's what they're for.
>
> Cheers,
> Nick.
>
More information about the Python-Dev
mailing list