GrahamDumpleton / wrapt

A Python module for decorators, wrappers and monkey patching.
BSD 2-Clause "Simplified" License
2.04k stars 230 forks source link

Replace various PyObject_IsInstance checks with cheaper PyObject_TypeCheck #100

Open ionelmc opened 7 years ago

ionelmc commented 7 years ago

This idea originated here: https://github.com/ionelmc/python-lazy-object-proxy/pull/18

Perhaps wrapt could do this as well. Opinions?

GrahamDumpleton commented 7 years ago

Would have to know where you are proposing the change be made. There are use cases for wrapt module proxy objects whereby users will create a class which derives from the wrapt proxy type. If an exact match is used, then presumably that case would fail.

ionelmc commented 7 years ago

PyObject_TypeCheck returns true if the object o is of type type or a subtype of type. It's basically a simpler check that don't involve __instancecheck__.

ionelmc commented 7 years ago

About where, all the places that have code like:

    if (PyObject_IsInstance(o1, (PyObject *)&WraptObjectProxy_Type))
        o1 = ((WraptObjectProxyObject *)o1)->wrapped;
ionelmc commented 7 years ago

And yes, I'm quite lazy, I'm just putting this idea up for discussion xD