Skip to content

Commit cde8a6d

Browse files
Don't use a custom type slot return converter; instead special case type slot functions during generation
1 parent 972d0db commit cde8a6d

File tree

3 files changed

+6
-20
lines changed

3 files changed

+6
-20
lines changed

Lib/test/clinic.test.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5350,7 +5350,6 @@ Test___init__(PyObject *self, PyObject *args, PyObject *kwargs)
53505350
{
53515351
int return_value = -1;
53525352
PyTypeObject *base_tp = TestType;
5353-
long _return_value;
53545353

53555354
if ((Py_IS_TYPE(self, base_tp) ||
53565355
Py_TYPE(self)->tp_new == base_tp->tp_new) &&
@@ -5362,19 +5361,15 @@ Test___init__(PyObject *self, PyObject *args, PyObject *kwargs)
53625361
!_PyArg_NoKeywords("Test", kwargs)) {
53635362
goto exit;
53645363
}
5365-
_return_value = Test___init___impl((TestObj *)self);
5366-
if ((_return_value == -1) && PyErr_Occurred()) {
5367-
goto exit;
5368-
}
5369-
return_value = PyLong_FromLong(_return_value);
5364+
return_value = Test___init___impl((TestObj *)self);
53705365

53715366
exit:
53725367
return return_value;
53735368
}
53745369

53755370
static long
53765371
Test___init___impl(TestObj *self)
5377-
/*[clinic end generated code: output=daf6ee12c4e443fb input=311af0dc7f17e8e9]*/
5372+
/*[clinic end generated code: output=9f3704989ab1f6eb input=311af0dc7f17e8e9]*/
53785373

53795374

53805375
/*[clinic input]

Lib/test/test_clinic.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2651,7 +2651,6 @@ def test_cli_converters(self):
26512651
long()
26522652
Py_ssize_t()
26532653
size_t()
2654-
type_slot_int()
26552654
unsigned_int()
26562655
unsigned_long()
26572656
@@ -3937,7 +3936,7 @@ def test_Function_and_Parameter_reprs(self):
39373936
cls=None,
39383937
c_basename=None,
39393938
full_name='foofoo',
3940-
return_converter=clinic.type_slot_int_return_converter(),
3939+
return_converter=clinic.int_return_converter(),
39413940
kind=clinic.FunctionKind.METHOD_INIT,
39423941
coexist=False
39433942
)

Tools/clinic/clinic.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,7 +1612,8 @@ def render_function(
16121612
for converter in converters:
16131613
converter.set_template_dict(template_dict)
16141614

1615-
f.return_converter.render(f, data)
1615+
if f.kind not in {SETTER, METHOD_INIT}:
1616+
f.return_converter.render(f, data)
16161617
template_dict['impl_return_type'] = f.return_converter.type
16171618

16181619
template_dict['declarations'] = libclinic.format_escape("\n".join(data.declarations))
@@ -4558,15 +4559,6 @@ class int_return_converter(long_return_converter):
45584559
cast = '(long)'
45594560

45604561

4561-
class type_slot_int_return_converter(long_return_converter):
4562-
"""Special return converter for type slots functions that return int."""
4563-
type = 'int'
4564-
cast = '(long)'
4565-
4566-
def render(self, function: Function, data: CRenderData) -> None:
4567-
pass
4568-
4569-
45704562
class unsigned_long_return_converter(long_return_converter):
45714563
type = 'unsigned long'
45724564
conversion_fn = 'PyLong_FromUnsignedLong'
@@ -5098,7 +5090,7 @@ def resolve_return_converter(
50985090
fail(f"Badly formed annotation for {full_name!r}: {forced_converter!r}")
50995091

51005092
if self.kind in {METHOD_INIT, SETTER}:
5101-
return type_slot_int_return_converter()
5093+
return int_return_converter()
51025094
return CReturnConverter()
51035095

51045096
def parse_cloned_function(self, names: FunctionNames, existing: str) -> None:

0 commit comments

Comments
 (0)