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
Override return converter during parsing
  • Loading branch information
erlend-aasland committed Mar 1, 2024
commit adbe7cb19b3640384a11972e696a44154879aa89
8 changes: 6 additions & 2 deletions Lib/test/clinic.test.c
10000
Original file line number Diff line number Diff line change
Expand Up @@ -5004,12 +5004,16 @@ Test_property_set_impl(TestObj *self, PyObject *value);
static int
Test_property_set(TestObj *self, PyObject *value, void *Py_UNUSED(context))
{
return Test_property_set_impl(self, value);
int return_value;

return_value = Test_property_set_impl(self, value);

return return_value;
}

static int
Test_property_set_impl(TestObj *self, PyObject *value)
/*[clinic end generated code: output=9797cd03c5204ddb input=3bc3f46a23c83a88]*/
/*[clinic end generated code: output=d51023f17c4ac3a1 input=3bc3f46a23c83a88]*/

/*[clinic input]
output push
Expand Down
4 changes: 2 additions & 2 deletions Lib/test/test_clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2647,11 +2647,11 @@ def test_cli_converters(self):
bool()
double()
float()
init()
int()
long()
Py_ssize_t()
size_t()
type_slot_int()
unsigned_int()
unsigned_long()

Expand Down Expand Up @@ -3937,7 +3937,7 @@ def test_Function_and_Parameter_reprs(self):
cls=None,
c_basename=None,
full_name='foofoo',
return_converter=clinic.init_return_converter(),
return_converter=clinic.type_slot_int_return_converter(),
kind=clinic.FunctionKind.METHOD_INIT,
coexist=False
)
Expand Down
23 changes: 7 additions & 16 deletions Tools/clinic/clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1613,11 +1613,7 @@ def render_function(
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
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)
Expand Down Expand Up @@ -4562,18 +4558,13 @@ class int_return_converter(long_return_converter):
cast = '(long)'


class init_return_converter(long_return_converter):
"""
Special return converter for __init__ functions.
"""
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: ...
def render(self, function: Function, data: CRenderData) -> None:
pass


class unsigned_long_return_converter(long_return_converter):
Expand Down Expand Up @@ -5106,8 +5097,8 @@ def resolve_return_converter(
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 type_slot_int_return_converter()
return CReturnConverter()

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