From 6827f19ad58b6af5779c4a6363d936943e4964fc Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Mon, 31 Jul 2023 13:16:40 +0200 Subject: [PATCH] gh-106368: Add test for Argument Clinic misbehaving custom converter_init() --- Lib/test/test_clinic.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Lib/test/test_clinic.py b/Lib/test/test_clinic.py index 3ce27d1dd6b487..2f94f0168c9166 100644 --- a/Lib/test/test_clinic.py +++ b/Lib/test/test_clinic.py @@ -318,6 +318,26 @@ def test_unknown_destination_command(self): 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):