|
15 | 15 | from libclinic.return_converters import CReturnConverter, return_converters |
16 | 16 |
|
17 | 17 |
|
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 | | - |
26 | 18 | @dc.dataclass(frozen=True, slots=True, kw_only=True) |
27 | 19 | 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 |
30 | 28 |
|
31 | 29 | @property |
32 | 30 | def error_value(self) -> str: |
33 | 31 | """The value returned by the slot function on error.""" |
34 | 32 | return 'NULL' if self.return_type.endswith('*') else '-1' |
35 | 33 |
|
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]() |
39 | 36 |
|
40 | 37 |
|
41 | 38 | # Maps the name of a special method to its slot. A name listed here must |
42 | 39 | # not be in dsl_parser.unsupported_special_methods. |
43 | 40 | 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'), |
46 | 43 | } |
0 commit comments