summaryrefslogtreecommitdiffstats
path: root/Tools/clinic
diff options
context:
space:
mode:
authorErlend E. Aasland <erlend@python.org>2024-03-04 12:51:28 (GMT)
committerGitHub <noreply@github.com>2024-03-04 12:51:28 (GMT)
commitcfbdce72083fca791947cbb18114115c90738d99 (patch)
tree730afadc2f66906e34a6cbf077dcb5de3ca5b00c /Tools/clinic
parent45a92436c5c42ca100f3ea0de9e7d37f1a97439b (diff)
downloadcpython-cfbdce72083fca791947cbb18114115c90738d99.zip
cpython-cfbdce72083fca791947cbb18114115c90738d99.tar.gz
cpython-cfbdce72083fca791947cbb18114115c90738d99.tar.bz2
gh-114258: Argument Clinic: refactor getset implementation (#116170)
* Move param guard to param state machine * Override return converter during parsing * Don't use a custom type slot return converter; instead special case type slot functions during generation.
Diffstat (limited to 'Tools/clinic')
-rwxr-xr-xTools/clinic/clinic.py35
1 files changed, 10 insertions, 25 deletions
diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py
index 80da035..0a85462 100755
--- a/Tools/clinic/clinic.py
+++ b/Tools/clinic/clinic.py
@@ -859,9 +859,6 @@ class CLanguage(Language):
limited_capi = False
parsearg: str | None
- if f.kind in {GETTER, SETTER} and parameters:
- fail(f"@{f.kind.name.lower()} method cannot define parameters")
-
if not parameters:
parser_code: list[str] | None
if f.kind is GETTER:
@@ -1615,12 +1612,9 @@ class CLanguage(Language):
for converter in converters:
converter.set_template_dict(template_dict)
- f.return_converter.render(f, data)
- if f.kind is SETTER:
- # All setters return an int.
- template_dict['impl_return_type'] = 'int'
- else:
- template_dict['impl_return_type'] = f.return_converter.type
+ if f.kind not in {SETTER, METHOD_INIT}:
+ f.return_converter.render(f, data)
+ template_dict['impl_return_type'] = f.return_converter.type
template_dict['declarations'] = libclinic.format_escape("\n".join(data.declarations))
template_dict['initializers'] = "\n\n".join(data.initializers)
@@ -4565,20 +4559,6 @@ class int_return_converter(long_return_converter):
cast = '(long)'
-class init_return_converter(long_return_converter):
- """
- Special return converter for __init__ functions.
- """
- type = 'int'
- cast = '(long)'
-
- def render(
- self,
- function: Function,
- data: CRenderData
- ) -> None: ...
-
-
class unsigned_long_return_converter(long_return_converter):
type = 'unsigned long'
conversion_fn = 'PyLong_FromUnsignedLong'
@@ -5111,8 +5091,8 @@ class DSLParser:
except ValueError:
fail(f"Badly formed annotation for {full_name!r}: {forced_converter!r}")
- if self.kind is METHOD_INIT:
- return init_return_converter()
+ if self.kind in {METHOD_INIT, SETTER}:
+ return int_return_converter()
return CReturnConverter()
def parse_cloned_function(self, names: FunctionNames, existing: str) -> None:
@@ -5294,6 +5274,11 @@ class DSLParser:
if not self.indent.infer(line):
return self.next(self.state_function_docstring, line)
+ assert self.function is not None
+ if self.function.kind in {GETTER, SETTER}:
+ getset = self.function.kind.name.lower()
+ fail(f"@{getset} methods cannot define parameters")
+
self.parameter_continuation = ''
return self.next(self.state_parameter, line)