[pypy-commit] pypy py3k: there is no consistency between raising TypeError or AttributeError in these cases

antocuni noreply at buildbot.pypy.org
Tue Sep 25 17:15:22 CEST 2012


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: py3k
Changeset: r57581:bb8cb13add7f
Date: 2012-09-25 11:44 +0200
http://bitbucket.org/pypy/pypy/changeset/bb8cb13add7f/

Log:	there is no consistency between raising TypeError or AttributeError
	in these cases

diff --git a/lib-python/3.2/test/test_funcattrs.py b/lib-python/3.2/test/test_funcattrs.py
--- a/lib-python/3.2/test/test_funcattrs.py
+++ b/lib-python/3.2/test/test_funcattrs.py
@@ -68,7 +68,7 @@
         self.assertEqual(len(c), 1)
         # don't have a type object handy
         self.assertEqual(c[0].__class__.__name__, "cell")
-        self.cannot_set_attr(f, "__closure__", c, AttributeError)
+        self.cannot_set_attr(f, "__closure__", c, (AttributeError, TypeError))
 
     def test_empty_cell(self):
         def f(): print(a)
@@ -87,7 +87,7 @@
         self.b.__name__ = 'd'
         self.assertEqual(self.b.__name__, 'd')
         # __name__ and __name__ must be a string
-        self.cannot_set_attr(self.b, '__name__', 7, TypeError)
+        self.cannot_set_attr(self.b, '__name__', 7, (AttributeError, TypeError))
         # __name__ must be available when in restricted mode. Exec will raise
         # AttributeError if __name__ is not available on f.
         s = """def f(): pass\nf.__name__"""
@@ -158,15 +158,15 @@
 
     def test___class__(self):
         self.assertEqual(self.fi.a.__self__.__class__, self.F)
-        self.cannot_set_attr(self.fi.a, "__class__", self.F, TypeError)
+        self.cannot_set_attr(self.fi.a, "__class__", self.F, (AttributeError, TypeError))
 
     def test___func__(self):
         self.assertEqual(self.fi.a.__func__, self.F.a)
-        self.cannot_set_attr(self.fi.a, "__func__", self.F.a, AttributeError)
+        self.cannot_set_attr(self.fi.a, "__func__", self.F.a, (AttributeError, TypeError))
 
     def test___self__(self):
         self.assertEqual(self.fi.a.__self__, self.fi)
-        self.cannot_set_attr(self.fi.a, "__self__", self.fi, AttributeError)
+        self.cannot_set_attr(self.fi.a, "__self__", self.fi, (AttributeError, TypeError))
 
     def test___func___non_method(self):
         # Behavior should be the same when a method is added via an attr
@@ -216,10 +216,10 @@
 
 class FunctionDictsTest(FuncAttrsTest):
     def test_setting_dict_to_invalid(self):
-        self.cannot_set_attr(self.b, '__dict__', None, TypeError)
+        self.cannot_set_attr(self.b, '__dict__', None, (AttributeError, TypeError))
         from collections import UserDict
         d = UserDict({'known_attr': 7})
-        self.cannot_set_attr(self.fi.a.__func__, '__dict__', d, TypeError)
+        self.cannot_set_attr(self.fi.a.__func__, '__dict__', d, (AttributeError, TypeError))
 
     def test_setting_dict_to_valid(self):
         d = {'known_attr': 7}
@@ -240,7 +240,7 @@
     def test_delete___dict__(self):
         try:
             del self.b.__dict__
-        except TypeError:
+        except (TypeError, AttributeError):
             pass
         else:
             self.fail("deleting function dictionary should raise TypeError")


More information about the pypy-commit mailing list