Author: Philip Jenvey <[email protected]>
Branch: py3k
Changeset: r84516:6c7f6b69aa0c
Date: 2016-05-18 18:40 -0700
http://bitbucket.org/pypy/pypy/changeset/6c7f6b69aa0c/

Log:    slot shadowing now a ValueError

diff --git a/pypy/objspace/std/test/test_typeobject.py 
b/pypy/objspace/std/test/test_typeobject.py
--- a/pypy/objspace/std/test/test_typeobject.py
+++ b/pypy/objspace/std/test/test_typeobject.py
@@ -1071,6 +1071,16 @@
         class D(A, B):     # "best base" is A
             __slots__ = ("__weakref__",)
 
+    def test_slot_shadows_class_variable(self):
+        try:
+            class X:
+                __slots__ = ["foo"]
+                foo = None
+        except ValueError as e:
+            assert str(e) == "'foo' in __slots__ conflicts with class variable"
+        else:
+            assert False, "ValueError expected"
+
     def test_metaclass_calc(self):
         """
         # issue1294232: correct metaclass calculation
diff --git a/pypy/objspace/std/typeobject.py b/pypy/objspace/std/typeobject.py
--- a/pypy/objspace/std/typeobject.py
+++ b/pypy/objspace/std/typeobject.py
@@ -1063,7 +1063,11 @@
         raise oefmt(space.w_TypeError, "__slots__ must be identifiers")
     # create member
     slot_name = mangle(slot_name, w_self.name)
-    if slot_name not in w_self.dict_w:
+    if slot_name in w_self.dict_w:
+        raise oefmt(space.w_ValueError,
+                    "'%s' in __slots__ conflicts with class variable",
+                    slot_name.decode('utf-8'))
+    else:
         # Force interning of slot names.
         slot_name = space.str_w(space.new_interned_str(slot_name))
         # in cpython it is ignored less, but we probably don't care
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to