From a83150c6381d3f633978476979f0a8446ac82171 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Thu, 15 Feb 2024 15:43:50 +0100 Subject: [PATCH 1/2] gh-113317: Argument Clinic: inline required_type_for_self_for_parser() in self converter --- Tools/clinic/clinic.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index 77d492a386651f..9f92051f524908 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -4402,14 +4402,6 @@ def correct_name_for_self( return "PyTypeObject *", "type" raise AssertionError(f"Unhandled type of function f: {f.kind!r}") -def required_type_for_self_for_parser( - f: Function -) -> str | None: - type, _ = correct_name_for_self(f) - if f.kind in (METHOD_INIT, METHOD_NEW, STATIC_METHOD, CLASS_METHOD): - return type - return None - class self_converter(CConverter): """ @@ -4474,7 +4466,11 @@ def pre_render(self) -> None: @property def parser_type(self) -> str: assert self.type is not None - return required_type_for_self_for_parser(self.function) or self.type + f = self.function + if f.kind in (METHOD_INIT, METHOD_NEW, STATIC_METHOD, CLASS_METHOD): + tp, _ = correct_name_for_self(f) + return tp + return self.type def render(self, parameter: Parameter, data: CRenderData) -> None: """ From 0bb534426b140d482f1c05d4c6fc375b5afa1f9a Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Thu, 15 Feb 2024 16:38:39 +0100 Subject: [PATCH 2/2] Update Tools/clinic/clinic.py Co-authored-by: Alex Waygood --- Tools/clinic/clinic.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index 9f92051f524908..7e657351b3f629 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -4466,9 +4466,8 @@ def pre_render(self) -> None: @property def parser_type(self) -> str: assert self.type is not None - f = self.function - if f.kind in (METHOD_INIT, METHOD_NEW, STATIC_METHOD, CLASS_METHOD): - tp, _ = correct_name_for_self(f) + if self.function.kind in {METHOD_INIT, METHOD_NEW, STATIC_METHOD, CLASS_METHOD}: + tp, _ = correct_name_for_self(self.function) return tp return self.type