10000 gh-114258: Argument Clinic: refactor getset implementation by erlend-aasland · Pull Request #116170 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-114258: Argument Clinic: refactor getset implementation #116170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Don't use a custom type slot return converter; instead special case t…
…ype slot functions during generation
  • Loading branch information
erlend-aasland committed Mar 1, 2024
commit cde8a6d4b66a5028cfaa7c2dae6b67c68c2ba5bc
9 changes: 2 additions & 7 deletions Lib/test/clinic.test.c
Original file line number Diff line number Diff line change
Expand Up @@ -5350,7 +5350,6 @@ Test___init__(PyObject *self, PyObject *args, PyObject *kwargs)
{
int return_value = -1;
PyTypeObject *base_tp = TestType;
long _return_value;

if ((Py_IS_TYPE(self, base_tp) ||
Py_TYPE(self)->tp_new == base_tp->tp_new) &&
Expand All @@ -5362,19 +5361,15 @@ Test___init__(PyObject *self, PyObject *args, PyObject *kwargs)
!_PyArg_NoKeywords("Test", kwargs)) {
goto exit;
}
_return_value = Test___init___impl((TestObj *)self);
if ((_return_value == -1) && PyErr_Occurred()) {
goto exit;
}
return_value = PyLong_FromLong(_return_value);
return_value = Test___init___impl((TestObj *)self);

exit:
return return_value;
}

static long
Test___init___impl(TestObj *self)
/*[clinic end generated code: output=daf6ee12c4e443fb input=311af0dc7f17e8e9]*/
/*[clinic end generated code: output=9f3704989ab1f6eb input=311af0dc7f17e8e9]*/


/*[clinic input]
Expand Down
3 changes: 1 addition & 2 deletions Lib/test/test_clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2651,7 +2651,6 @@ def test_cli_converters(self):
long()
Py_ssize_t()
size_t()
type_slot_int()
unsigned_int()
unsigned_long()

Expand Down Expand Up @@ -3937,7 +3936,7 @@ def test_Function_and_Parameter_reprs(self):
cls=None,
c_basename=None,
full_name='foofoo',
return_converter=clinic.type_slot_int_return_converter(),
return_converter=clinic.int_return_converter(),
kind=clinic.FunctionKind.METHOD_INIT,
coexist=False
)
Expand Down
14 changes: 3 additions & 11 deletions Tools/clinic/clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1612,7 +1612,8 @@ def render_function(
for converter in converters:
converter.set_template_dict(template_dict)

f.return_converter.render(f, data)
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))
Expand Down Expand Up @@ -4558,15 +4559,6 @@ class int_return_converter(long_return_converter):
cast = '(long)'


class type_slot_int_return_converter(long_return_converter):
"""Special return converter for type slots functions that return int."""
type = 'int'
cast = '(long)'

def render(self, function: Function, data: CRenderData) -> None:
pass


class unsigned_long_return_converter(long_return_converter):
type = 'unsigned long'
conversion_fn = 'PyLong_FromUnsignedLong'
Expand Down Expand Up @@ -5098,7 +5090,7 @@ def resolve_return_converter(
fail(f"Badly formed annotation for {full_name!r}: {forced_converter!r}")

if self.kind in {METHOD_INIT, SETTER}:
return type_slot_int_return_converter()
return int_return_converter()
return CReturnConverter()

def parse_cloned_function(self, names: FunctionNames, existing: str) -> None:
Expand Down
0