Merge pull request #4537 from chdsbd/master

Bugfix: monkeypatch.delattr handles class descriptors
This commit is contained in:
Bruno Oliveira
2019-01-16 08:09:59 -02:00
committed by GitHub
4 changed files with 36 additions and 1 deletions

View File

@@ -181,6 +181,8 @@ class MonkeyPatch(object):
attribute is missing.
"""
__tracebackhide__ = True
import inspect
if name is notset:
if not isinstance(target, six.string_types):
raise TypeError(
@@ -194,7 +196,11 @@ class MonkeyPatch(object):
if raising:
raise AttributeError(name)
else:
self._setattr.append((target, name, getattr(target, name, notset)))
oldval = getattr(target, name, notset)
# Avoid class descriptors like staticmethod/classmethod.
if inspect.isclass(target):
oldval = target.__dict__.get(name, notset)
self._setattr.append((target, name, oldval))
delattr(target, name)
def setitem(self, dic, name, value):