Skip to content

Commit 2cda4e6

Browse files
Merge pull request #312 from bysiber/fix/weakfunctionproxy-expired-instance
Raise ReferenceError when bound method instance is garbage collected
2 parents 2ea0090 + 4d44747 commit 2cda4e6

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/wrapt/weakrefs.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,13 @@ def _unpack_self(self, *args):
103103
instance = self._self_instance and self._self_instance()
104104
function = self.__wrapped__ and self.__wrapped__
105105

106+
# If the wrapped function was originally a bound method but the
107+
# instance it was bound to has been garbage collected, raise a
108+
# ReferenceError rather than silently calling it as unbound.
109+
110+
if self._self_instance is not None and instance is None:
111+
raise ReferenceError("weakly-referenced object no longer exists")
112+
106113
# If the wrapped function was originally a bound function, for
107114
# which we retained a reference to the instance and the unbound
108115
# function we need to rebind the function and then call it. If

0 commit comments

Comments
 (0)