]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-106368: Add test for Argument Clinic misbehaving custom converter_init...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 31 Jul 2023 15:57:25 +0000 (08:57 -0700)
committerGitHub <noreply@github.com>
Mon, 31 Jul 2023 15:57:25 +0000 (15:57 +0000)
(cherry picked from commit 2c5d206b33e4cdcafaaaf1eeaa189c10de332dc5)

Co-authored-by: Erlend E. Aasland <erlend@python.org>
Lib/test/test_clinic.py

index 3d740910a57ae657ba6cd0e08b9d5266ab69af59..520cc51302212d8d5180181bbf6958e2e916aab6 100644 (file)
@@ -314,6 +314,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):