[pypy-commit] pypy stdlib-2.7.4-fixed-class: fixed support for class in stdlib 2.7.4

andrewsmedina noreply at buildbot.pypy.org
Tue Jul 30 00:23:50 CEST 2013


Author: Andrews Medina <andrewsmedina at gmail.com>
Branch: stdlib-2.7.4-fixed-class
Changeset: r65802:ab9512fa99c0
Date: 2013-07-29 10:23 -0300
http://bitbucket.org/pypy/pypy/changeset/ab9512fa99c0/

Log:	fixed support for class in stdlib 2.7.4

diff --git a/pypy/module/__builtin__/interp_classobj.py b/pypy/module/__builtin__/interp_classobj.py
--- a/pypy/module/__builtin__/interp_classobj.py
+++ b/pypy/module/__builtin__/interp_classobj.py
@@ -116,6 +116,9 @@
         return None
 
     def descr_getattribute(self, space, w_attr):
+        if not space.isinstance_w(w_attr, space.w_str):
+            msg = "attribute name must be a string"
+            raise OperationError(space.w_TypeError, space.wrap(msg))
         name = unwrap_attr(space, w_attr)
         if name and name[0] == "_":
             if name == "__dict__":
@@ -137,6 +140,9 @@
         return space.call_function(w_descr_get, w_value, space.w_None, self)
 
     def descr_setattr(self, space, w_attr, w_value):
+        if not space.isinstance_w(w_attr, space.w_str):
+            msg = "attribute name must be a string"
+            raise OperationError(space.w_TypeError, space.wrap(msg))
         name = unwrap_attr(space, w_attr)
         if name and name[0] == "_":
             if name == "__dict__":
@@ -370,6 +376,9 @@
             return None
 
     def descr_getattribute(self, space, w_attr):
+        if not space.isinstance_w(w_attr, space.w_str):
+            msg = "attribute name must be a string"
+            raise OperationError(space.w_TypeError, space.wrap(msg))
         name = space.str_w(w_attr)
         if len(name) >= 8 and name[0] == '_':
             if name == "__dict__":
@@ -379,6 +388,9 @@
         return self.getattr(space, name)
 
     def descr_setattr(self, space, w_name, w_value):
+        if not space.isinstance_w(w_name, space.w_str):
+            msg = "attribute name must be a string"
+            raise OperationError(space.w_TypeError, space.wrap(msg))
         name = unwrap_attr(space, w_name)
         w_meth = self.getattr_from_class(space, '__setattr__')
         if name and name[0] == "_":
diff --git a/pypy/module/__builtin__/test/test_classobj.py b/pypy/module/__builtin__/test/test_classobj.py
--- a/pypy/module/__builtin__/test/test_classobj.py
+++ b/pypy/module/__builtin__/test/test_classobj.py
@@ -1078,6 +1078,13 @@
             b = 2
         assert self.is_strdict(A)
 
+    def test_attr_slots(self):
+        class C:
+            pass
+        for c in C, C():
+            raises(TypeError, type(c).__getattribute__, c, [])
+            raises(TypeError, type(c).__setattr__, c, [], [])
+
 class AppTestOldStyleMapDict(AppTestOldstyle):
     spaceconfig = {"objspace.std.withmapdict": True}
 


More information about the pypy-commit mailing list