Skip to content

Commit

Permalink
Clean up C version of instance check and add change note.
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamDumpleton committed Mar 5, 2022
1 parent a81b675 commit 9399d7c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
6 changes: 6 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ Version 1.14.0
The replacement function is exposed as `wrapt.formatargspec()` if need it
for your own code.

* When using a decorator on a class, `isinstance()` checks wouldn't previously
work as expected and you had to manually use `Type.__wrapped__` to access
the real type when doing instance checks. The `__instancecheck__` hook is now
implemented such that you don't have to use `Type.__wrapped__` instead of
`Type` as last argument to `isinstance()`.

**New Features**

* Binary wheels provided on PyPi for `aarch64` Linux systems and macOS
Expand Down
9 changes: 3 additions & 6 deletions src/wrapt/_wrappers.c
Original file line number Diff line number Diff line change
Expand Up @@ -2551,21 +2551,18 @@ static PyObject *WraptFunctionWrapperBase_instancecheck(
PyObject *result = NULL;

int check = 0;

if (!self->object_proxy.wrapped) {
PyErr_SetString(PyExc_ValueError, "wrapper has not been initialized");
return NULL;
}

object = PyObject_GetAttrString(self, "__wrapped__");
if (!object) {
PyErr_Clear();
}
check = PyObject_IsInstance(instance, self->object_proxy.wrapped);

check = PyObject_IsInstance(instance, object);
Py_XDECREF(object);
if (check < 0) {
return NULL;
}

result = check ? Py_True : Py_False;

Py_INCREF(result);
Expand Down

0 comments on commit 9399d7c

Please sign in to comment.