[Python-Dev] C-level duck typing (original) (raw)
Dag Sverre Seljebotn d.s.seljebotn at astro.uio.no
Wed May 16 10:25:21 CEST 2012
- Previous message: [Python-Dev] C-level duck typing
- Next message: [Python-Dev] C-level duck typing
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 05/16/2012 10:11 AM, Nick Coghlan wrote:
Use PyObjectHasAttr, 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.
- Previous message: [Python-Dev] C-level duck typing
- Next message: [Python-Dev] C-level duck typing
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]