diff options
author | Benjamin Peterson <benjamin@python.org> | 2014-08-17 23:26:58 -0500 |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2014-08-17 23:26:58 -0500 |
commit | dd219bfd247287287646a9c00687ec67ddc5a9a9 (patch) | |
tree | 029eae0d037e3e0059b21b902d37fd97579a1915 | |
parent | 535398fdae8dacb8311c3beed055eec12d64a71b (diff) | |
download | six-dd219bfd247287287646a9c00687ec67ddc5a9a9.tar.gz |
fix add_metaclass when there is a __weakref__ or __dict__ slot (closes #88)
-rw-r--r-- | CHANGES | 3 | ||||
-rw-r--r-- | six.py | 4 | ||||
-rw-r--r-- | test_six.py | 4 |
3 files changed, 9 insertions, 2 deletions
@@ -6,6 +6,9 @@ This file lists the changes in each six version. Development version ------------------- +- Issue #88: Fix add_metaclass when the class has __slots__ containing + "__weakref__" or "__dict__". + - Issue #89: Make six use absolute imports. - Issue #85: Always accept *updated* and *assigned* arguments for wraps(). @@ -719,14 +719,14 @@ def add_metaclass(metaclass): """Class decorator for creating a class with a metaclass.""" def wrapper(cls): orig_vars = cls.__dict__.copy() - orig_vars.pop('__dict__', None) - orig_vars.pop('__weakref__', None) slots = orig_vars.get('__slots__') if slots is not None: if isinstance(slots, str): slots = [slots] for slots_var in slots: orig_vars.pop(slots_var) + orig_vars.pop('__dict__', None) + orig_vars.pop('__weakref__', None) return metaclass(cls.__name__, cls.__bases__, orig_vars) return wrapper diff --git a/test_six.py b/test_six.py index 1536276..0125d6b 100644 --- a/test_six.py +++ b/test_six.py @@ -730,3 +730,7 @@ def test_add_metaclass(): py.test.raises(AttributeError, setattr, instance, "a", "baz") py.test.raises(AttributeError, setattr, instance, "b", "baz") + class MySlotsWeakref(object): + __slots__ = "__weakref__", + MySlotsWeakref = six.add_metaclass(Meta)(MySlotsWeakref) + assert type(MySlotsWeakref) is Meta |