diff options
-rw-r--r-- | CHANGES | 3 | ||||
-rw-r--r-- | six.py | 8 | ||||
-rw-r--r-- | test_six.py | 11 |
3 files changed, 20 insertions, 2 deletions
@@ -6,6 +6,9 @@ This file lists the changes in each six version. Development version ------------------- +- Issue #47: Fix add_metaclass on classes with a string for the __slots__ + variable. + - Issue #44: Fix interpretation of backslashes on Python 2 in the u() function. - Pull request #21: Add import mapping for urllib's proxy_bypass function. @@ -581,7 +581,11 @@ def add_metaclass(metaclass): orig_vars = cls.__dict__.copy() orig_vars.pop('__dict__', None) orig_vars.pop('__weakref__', None) - for slots_var in orig_vars.get('__slots__', ()): - orig_vars.pop(slots_var) + 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) return metaclass(cls.__name__, cls.__bases__, orig_vars) return wrapper diff --git a/test_six.py b/test_six.py index 81b424f..7f92617 100644 --- a/test_six.py +++ b/test_six.py @@ -630,3 +630,14 @@ def test_add_metaclass(): instance = MySlots() instance.a = "foo" py.test.raises(AttributeError, setattr, instance, "c", "baz") + + # Test a class with string for slots. + class MyStringSlots(object): + __slots__ = "ab" + MyStringSlots = six.add_metaclass(Meta1)(MyStringSlots) + assert MyStringSlots.__slots__ == "ab" + instance = MyStringSlots() + instance.ab = "foo" + py.test.raises(AttributeError, setattr, instance, "a", "baz") + py.test.raises(AttributeError, setattr, instance, "b", "baz") + |