Skip to content

Commit 33a0522

Browse files
committed
More compact
1 parent 1e0ba69 commit 33a0522

2 files changed

Lines changed: 15 additions & 11 deletions

File tree

‎Lib/test/test_clinic.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -861,11 +861,11 @@ def test_slot_with_parameters_and_return_type(self):
861861
# object are not supported yet; check the machinery with them.
862862
slots = {
863863
'__contains__': (
864-
SlotSpec(return_type='int', return_converter='int',
864+
SlotSpec(return_converter='int',
865865
parameters=(object_converter,)),
866866
),
867867
'__bool__': (
868-
SlotSpec(return_type='int', return_converter='int'),
868+
SlotSpec(return_converter='int'),
869869
),
870870
}
871871
block = """
@@ -3366,9 +3366,9 @@ def test_slot_parameters(self):
33663366
# __getitem__ is not supported yet: the parameters select the slot
33673367
# (sq_item or mp_subscript).
33683368
slots = (
3369-
SlotSpec(return_type='PyObject *', return_converter='object',
3369+
SlotSpec(return_converter='object',
33703370
parameters=(Py_ssize_t_converter,)),
3371-
SlotSpec(return_type='PyObject *', return_converter='object',
3371+
SlotSpec(return_converter='object',
33723372
parameters=(object_converter,)),
33733373
)
33743374
block = """
@@ -3396,9 +3396,9 @@ def test_slot_parameter_errors(self):
33963396
# (tp_setattro and tp_setattr) make the error message list the
33973397
# alternatives.
33983398
slots = (
3399-
SlotSpec(return_type='int', return_converter='int',
3399+
SlotSpec(return_converter='int',
34003400
parameters=(object_converter, object_converter)),
3401-
SlotSpec(return_type='int', return_converter='int',
3401+
SlotSpec(return_converter='int',
34023402
parameters=(str_converter, object_converter)),
34033403
)
34043404
errors = [

‎Tools/clinic/libclinic/slots.py‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,21 @@
1515
from typing import Final
1616

1717
from libclinic.converter import CConverter
18+
from libclinic.return_converters import return_converters
1819

1920

2021
@dc.dataclass(frozen=True, slots=True, kw_only=True)
2122
class SlotSpec:
22-
# The C return type of the slot function.
23-
return_type: str
24-
# The name of the return converter which declares `return_type`.
23+
# The name of the return converter of the implementation function.
2524
return_converter: str
2625
# The converter classes of the parameters, excluding self.
2726
parameters: tuple[type[CConverter], ...] = ()
2827

28+
@property
29+
def return_type(self) -> str:
30+
"""The C return type of the slot function."""
31+
return return_converters[self.return_converter]().type
32+
2933
@property
3034
def error_value(self) -> str:
3135
"""The value returned by the slot function on error."""
@@ -45,9 +49,9 @@ def describe(self) -> str:
4549
# listed here must not be in dsl_parser.unsupported_special_methods.
4650
SLOTS: Final[dict[str, tuple[SlotSpec, ...]]] = {
4751
'__next__': (
48-
SlotSpec(return_type='PyObject *', return_converter='object'),
52+
SlotSpec(return_converter='object'),
4953
),
5054
'__len__': (
51-
SlotSpec(return_type='Py_ssize_t', return_converter='Py_ssize_t'),
55+
SlotSpec(return_converter='Py_ssize_t'),
5256
),
5357
}

0 commit comments

Comments
 (0)