diff options
author | Erlend E. Aasland <erlend@python.org> | 2023-08-15 14:00:52 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-15 14:00:52 (GMT) |
commit | e90036c9bdf25621c15207a9cabd119fb5366c27 (patch) | |
tree | 630b0a894d71d46a868e0b0c8f4fc452f9dbac67 /Tools/clinic | |
parent | 6515ec3d3d5acd3d0b99c88794bdec09f0831e5b (diff) | |
download | cpython-e90036c9bdf25621c15207a9cabd119fb5366c27.zip cpython-e90036c9bdf25621c15207a9cabd119fb5366c27.tar.gz cpython-e90036c9bdf25621c15207a9cabd119fb5366c27.tar.bz2 |
gh-107880: Argument Clinic: Fix regression in gh-107885 (#107974)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Diffstat (limited to 'Tools/clinic')
-rwxr-xr-x | Tools/clinic/clinic.py | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index 1e0303c..11dbfb3 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -4840,6 +4840,21 @@ class DSLParser: self.next(self.state_modulename_name, line) + def update_function_kind(self, fullname: str) -> None: + fields = fullname.split('.') + name = fields.pop() + _, cls = self.clinic._module_and_class(fields) + if name in unsupported_special_methods: + fail(f"{name!r} is a special method and cannot be converted to Argument Clinic!") + if name == '__new__': + if (self.kind is not CLASS_METHOD) or (not cls): + fail("'__new__' must be a class method!") + self.kind = METHOD_NEW + elif name == '__init__': + if (self.kind is not CALLABLE) or (not cls): + fail("'__init__' must be a normal method, not a class or static method!") + self.kind = METHOD_INIT + def state_modulename_name(self, line: str) -> None: # looking for declaration, which establishes the leftmost column # line should be @@ -4888,6 +4903,7 @@ class DSLParser: function_name = fields.pop() module, cls = self.clinic._module_and_class(fields) + self.update_function_kind(full_name) overrides: dict[str, Any] = { "name": function_name, "full_name": full_name, @@ -4948,20 +4964,9 @@ class DSLParser: function_name = fields.pop() module, cls = self.clinic._module_and_class(fields) - fields = full_name.split('.') - if fields[-1] in unsupported_special_methods: - fail(f"{fields[-1]} is a special method and cannot be converted to Argument Clinic! (Yet.)") - - if fields[-1] == '__new__': - if (self.kind is not CLASS_METHOD) or (not cls): - fail("__new__ must be a class method!") - self.kind = METHOD_NEW - elif fields[-1] == '__init__': - if (self.kind is not CALLABLE) or (not cls): - fail("__init__ must be a normal method, not a class or static method!") - self.kind = METHOD_INIT - if not return_converter: - return_converter = init_return_converter() + self.update_function_kind(full_name) + if self.kind is METHOD_INIT and not return_converter: + return_converter = init_return_converter() if not return_converter: return_converter = CReturnConverter() |