summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2014-08-17 23:26:58 -0500
committerBenjamin Peterson <benjamin@python.org>2014-08-17 23:26:58 -0500
commitdd219bfd247287287646a9c00687ec67ddc5a9a9 (patch)
tree029eae0d037e3e0059b21b902d37fd97579a1915
parent535398fdae8dacb8311c3beed055eec12d64a71b (diff)
downloadsix-dd219bfd247287287646a9c00687ec67ddc5a9a9.tar.gz
fix add_metaclass when there is a __weakref__ or __dict__ slot (closes #88)
-rw-r--r--CHANGES3
-rw-r--r--six.py4
-rw-r--r--test_six.py4
3 files changed, 9 insertions, 2 deletions
diff --git a/CHANGES b/CHANGES
index 056b19e..01c78c4 100644
--- a/CHANGES
+++ b/CHANGES
@@ -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().
diff --git a/six.py b/six.py
index 6940d0d..304f618 100644
--- a/six.py
+++ b/six.py
@@ -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