Skip to content

Commit cc5b4f7

Browse files
committed
Update
1 parent 06a5b69 commit cc5b4f7

3 files changed

Lines changed: 16 additions & 19 deletions

File tree

‎Lib/test/test_clinic.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -859,8 +859,8 @@ def test_slot_with_parameters_and_return_type(self):
859859
# Slots which take arguments or return something else than an
860860
# object are not supported yet; check the machinery with them.
861861
slots = {
862-
'__contains__': SlotSpec(return_type='int'),
863-
'__bool__': SlotSpec(return_type='int'),
862+
'__contains__': SlotSpec(return_converter='int'),
863+
'__bool__': SlotSpec(return_converter='int'),
864864
}
865865
block = """
866866
/*[clinic input]
@@ -3373,7 +3373,7 @@ class Foo "FooObject *" ""
33733373
"The parameters of '__getitem__' cannot have a default value"),
33743374
]
33753375
supported = unsupported_special_methods - {'__getitem__'}
3376-
with (mock.patch.dict(SLOTS, {'__getitem__': SlotSpec(return_type='PyObject *')}),
3376+
with (mock.patch.dict(SLOTS, {'__getitem__': SlotSpec(return_converter='object')}),
33773377
mock.patch.object(libclinic.dsl_parser,
33783378
'unsupported_special_methods', supported)):
33793379
for converter in "Py_ssize_t", "object":

‎Tools/clinic/libclinic/dsl_parser.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ def resolve_return_converter(
694694
return int_return_converter()
695695
if self.kind is SLOT:
696696
assert self.slot is not None
697-
return self.slot.return_converter()
697+
return self.slot.make_return_converter()
698698
return CReturnConverter()
699699

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

‎Tools/clinic/libclinic/slots.py‎

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,29 @@
1515
from libclinic.return_converters import CReturnConverter, return_converters
1616

1717

18-
# The return converter which declares each C return type of a slot.
19-
_RETURN_CONVERTERS: Final[dict[str, str]] = {
20-
'PyObject *': 'object',
21-
'Py_ssize_t': 'Py_ssize_t',
22-
'int': 'int',
23-
}
24-
25-
2618
@dc.dataclass(frozen=True, slots=True, kw_only=True)
2719
class SlotSpec:
28-
# The C return type of the slot function.
29-
return_type: str
20+
# The name of the return converter of the implementation function,
21+
# which declares the C return type of the slot function.
22+
return_converter: str
23+
24+
@property
25+
def return_type(self) -> str:
26+
"""The C return type of the slot function."""
27+
return self.make_return_converter().type
3028

3129
@property
3230
def error_value(self) -> str:
3331
"""The value returned by the slot function on error."""
3432
return 'NULL' if self.return_type.endswith('*') else '-1'
3533

36-
def return_converter(self) -> CReturnConverter:
37-
"""The return converter of the implementation function."""
38-
return return_converters[_RETURN_CONVERTERS[self.return_type]]()
34+
def make_return_converter(self) -> CReturnConverter:
35+
return return_converters[self.return_converter]()
3936

4037

4138
# Maps the name of a special method to its slot. A name listed here must
4239
# not be in dsl_parser.unsupported_special_methods.
4340
SLOTS: Final[dict[str, SlotSpec]] = {
44-
'__next__': SlotSpec(return_type='PyObject *'),
45-
'__len__': SlotSpec(return_type='Py_ssize_t'),
41+
'__next__': SlotSpec(return_converter='object'),
42+
'__len__': SlotSpec(return_converter='Py_ssize_t'),
4643
}

0 commit comments

Comments
 (0)