Skip to content

Commit

Permalink
gh-113317: Move Argument Clinic converters to sub-modules
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
vstinner committed Mar 14, 2024
1 parent c432df6 commit ee8d49d
Show file tree
Hide file tree
Showing 9 changed files with 1,358 additions and 1,305 deletions.
1,315 changes: 11 additions & 1,304 deletions Tools/clinic/clinic.py

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions Tools/clinic/libclinic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
Sentinels,
unspecified,
unknown,
TypeSet,
Null,
NULL,
)


Expand Down Expand Up @@ -68,6 +71,9 @@
"Sentinels",
"unspecified",
"unknown",
"TypeSet",
"Null",
"NULL",
]


Expand Down
19 changes: 19 additions & 0 deletions Tools/clinic/libclinic/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,3 +532,22 @@ def add_include(self, name: str, reason: str,
# these callables follow the same rules as those for "converters" above.
# note however that they will never be called with keyword-only parameters.
legacy_converters: ConverterDict = {}


def add_legacy_c_converter(
format_unit: str,
**kwargs: Any
) -> Callable[[CConverterClassT], CConverterClassT]:
"""
Adds a legacy converter.
"""
def closure(f: CConverterClassT) -> CConverterClassT:
added_f: Callable[..., CConverter]
if not kwargs:
added_f = f
else:
added_f = functools.partial(f, **kwargs)
if format_unit:
legacy_converters[format_unit] = added_f
return f
return closure
4 changes: 3 additions & 1 deletion Tools/clinic/libclinic/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import inspect
from typing import Final, Any, TYPE_CHECKING
if TYPE_CHECKING:
from clinic import Clinic, CReturnConverter, self_converter
from libclinic.converter import CConverter
from libclinic.misc_converters import self_converter
from libclinic.return_converter import CReturnConverter
from clinic import Clinic

from libclinic import VersionTuple, unspecified

Expand Down
Loading

0 comments on commit ee8d49d

Please sign in to comment.