Skip to content

Commit

Permalink
gh-113317: Argument Clinic: Add libclinic.converters module (#117315)
Browse files Browse the repository at this point in the history
Move the following converter classes to libclinic.converters:

* PyByteArrayObject_converter
* PyBytesObject_converter
* Py_UNICODE_converter
* Py_buffer_converter
* Py_complex_converter
* Py_ssize_t_converter
* bool_converter
* byte_converter
* char_converter
* defining_class_converter
* double_converter
* fildes_converter
* float_converter
* int_converter
* long_converter
* long_long_converter
* object_converter
* self_converter
* short_converter
* size_t_converter
* slice_index_converter
* str_converter
* unicode_converter
* unsigned_char_converter
* unsigned_int_converter
* unsigned_long_converter
* unsigned_long_long_converter
* unsigned_short_converter

Move also the following classes to libclinic.converters:

* buffer
* robuffer
* rwbuffer

Move the following functions to libclinic.converters:

* correct_name_for_self()
* r()
* str_converter_key()

Move Null and NULL to libclinic.utils.
  • Loading branch information
vstinner committed Apr 2, 2024
1 parent 9dae05e commit 5fd1897
Show file tree
Hide file tree
Showing 7 changed files with 1,259 additions and 1,215 deletions.
7 changes: 4 additions & 3 deletions Lib/test/test_clinic.py
Expand Up @@ -17,6 +17,7 @@
test_tools.skip_if_missing('clinic')
with test_tools.imports_under_tool('clinic'):
import libclinic
from libclinic.converters import int_converter, str_converter
import clinic
from clinic import DSLParser

Expand Down Expand Up @@ -924,7 +925,7 @@ def test_param(self):
self.assertEqual(2, len(function.parameters))
p = function.parameters['path']
self.assertEqual('path', p.name)
self.assertIsInstance(p.converter, clinic.int_converter)
self.assertIsInstance(p.converter, int_converter)

def test_param_default(self):
function = self.parse_function("""
Expand Down Expand Up @@ -1023,7 +1024,7 @@ def test_param_no_docstring(self):
""")
self.assertEqual(3, len(function.parameters))
conv = function.parameters['something_else'].converter
self.assertIsInstance(conv, clinic.str_converter)
self.assertIsInstance(conv, str_converter)

def test_param_default_parameters_out_of_order(self):
err = (
Expand Down Expand Up @@ -2040,7 +2041,7 @@ def test_legacy_converters(self):
block = self.parse('module os\nos.access\n path: "s"')
module, function = block.signatures
conv = (function.parameters['path']).converter
self.assertIsInstance(conv, clinic.str_converter)
self.assertIsInstance(conv, str_converter)

def test_legacy_converters_non_string_constant_annotation(self):
err = "Annotations must be either a name, a function call, or a string"
Expand Down

0 comments on commit 5fd1897

Please sign in to comment.