Skip to content

Commit ee8d49d

Browse files
committed
gh-113317: Move Argument Clinic converters to sub-modules
Move the following classes to new sub-modules: * libclinic.return_converters: * CReturnConverterAutoRegister * CReturnConverter * libclinic.int_converters: * bool_converter * char_converter * unsigned_char_converter * byte_converter * short_converter * unsigned_short_converter * int_converter * unsigned_int_converter * long_converter * unsigned_long_converter * long_long_converter * unsigned_long_long_converter * Py_ssize_t_converter * slice_index_converter * size_t_converter * libclinic.obj_converters: * fildes_converter * float_converter * double_converter * Py_complex_converter * object_converter * buffer * rwbuffer * robuffer * str_converter * PyBytesObject_converter * PyByteArrayObject_converter * unicode_converter * Py_UNICODE_converter * Py_buffer_converter * libclinic.misc_converters: * defining_class_converter * self_converter Move also Null, NULL and TypeSet to libclinic.utils.
1 parent c432df6 commit ee8d49d

File tree

9 files changed

+1358
-1305
lines changed

9 files changed

+1358
-1305
lines changed

Tools/clinic/clinic.py

+11-1,304
Large diffs are not rendered by default.

Tools/clinic/libclinic/__init__.py

+6
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
Sentinels,
3333
unspecified,
3434
unknown,
35+
TypeSet,
36+
Null,
37+
NULL,
3538
)
3639

3740

@@ -68,6 +71,9 @@
6871
"Sentinels",
6972
"unspecified",
7073
"unknown",
74+
"TypeSet",
75+
"Null",
76+
"NULL",
7177
]
7278

7379

Tools/clinic/libclinic/converter.py

+19
Original file line numberDiff line numberDiff line change
@@ -532,3 +532,22 @@ def add_include(self, name: str, reason: str,
532532
# these callables follow the same rules as those for "converters" above.
533533
# note however that they will never be called with keyword-only parameters.
534534
legacy_converters: ConverterDict = {}
535+
536+
537+
def add_legacy_c_converter(
538+
format_unit: str,
539+
**kwargs: Any
540+
) -> Callable[[CConverterClassT], CConverterClassT]:
541+
"""
542+
Adds a legacy converter.
543+
"""
544+
def closure(f: CConverterClassT) -> CConverterClassT:
545+
added_f: Callable[..., CConverter]
546+
if not kwargs:
547+
added_f = f
548+
else:
549+
added_f = functools.partial(f, **kwargs)
550+
if format_unit:
551+
legacy_converters[format_unit] = added_f
552+
return f
553+
return closure

Tools/clinic/libclinic/function.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
import inspect
77
from typing import Final, Any, TYPE_CHECKING
88
if TYPE_CHECKING:
9-
from clinic import Clinic, CReturnConverter, self_converter
109
from libclinic.converter import CConverter
10+
from libclinic.misc_converters import self_converter
11+
from libclinic.return_converter import CReturnConverter
12+
from clinic import Clinic
1113

1214
from libclinic import VersionTuple, unspecified
1315

0 commit comments

Comments
 (0)