Commits

1st1 committed 459d7e0

pep 362: Add Signature & Parameter immutability tests

Comments (0)

Files changed (1)

Lib/test/test_inspect.py

         with self.assertRaisesRegexp(ValueError, 'duplicate parameter name'):
             S((po, pk, args, kwargs2, ko))
 
+    def test_signature_immutability(self):
+        def test(a):
+            pass
+        sig = inspect.signature(test)
+
+        with self.assertRaises(AttributeError):
+            sig.foo = 'bar'
+
+        with self.assertRaises(TypeError):
+            sig.parameters['a'] = None
+
     def test_signature_on_noarg(self):
         def test():
             pass
         p = p.replace(name='1')
         self.assertEqual(str(p), '<1>')
 
+    def test_signature_parameter_immutability(self):
+        p = inspect.Parameter(None, kind=inspect.Parameter.POSITIONAL_ONLY)
+
+        with self.assertRaises(AttributeError):
+            p.foo = 'bar'
+
+        with self.assertRaises(AttributeError):
+            p.kind = 123
+
 
 class TestSignatureBind(unittest.TestCase):
     @staticmethod