]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-106368: Add test for Argument Clinic misbehaving custom converter_init() (#107496)
authorErlend E. Aasland <erlend@python.org>
Mon, 31 Jul 2023 11:50:03 +0000 (13:50 +0200)
committerGitHub <noreply@github.com>
Mon, 31 Jul 2023 11:50:03 +0000 (11:50 +0000)
Lib/test/test_clinic.py

index 3ce27d1dd6b487040ee065b5a662cea4f4334344..2f94f0168c9166ee87c7cf9919205559dce9c421 100644 (file)
@@ -318,6 +318,26 @@ class ClinicWholeFileTest(_ParserBase):
         msg = "unknown destination command 'nosuchcommand'"
         self.assertIn(msg, out)
 
+    def test_no_access_to_members_in_converter_init(self):
+        out = self.expect_failure("""
+            /*[python input]
+            class Custom_converter(CConverter):
+                converter = "some_c_function"
+                def converter_init(self):
+                    self.function.noaccess
+            [python start generated code]*/
+            /*[clinic input]
+            module test
+            test.fn
+                a: Custom
+            [clinic start generated code]*/
+        """)
+        msg = (
+            "Stepped on a land mine, trying to access attribute 'noaccess':\n"
+            "Don't access members of self.function inside converter_init!"
+        )
+        self.assertIn(msg, out)
+
 
 class ClinicGroupPermuterTest(TestCase):
     def _test(self, l, m, r, output):