Skip to content

Commit bc5356b

Browse files
gh-108494: Argument Clinic: fix support of Limited C API (GH-108536)
1 parent d909733 commit bc5356b

File tree

10 files changed

+147
-114
lines changed

10 files changed

+147
-114
lines changed

Lib/test/test_call.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ def test_varargs3(self):
6565
self.assertRaisesRegex(TypeError, msg, int.from_bytes, b'a', 'little', False)
6666

6767
def test_varargs1min(self):
68-
msg = r"get expected at least 1 argument, got 0"
68+
msg = (r"get\(\) takes at least 1 argument \(0 given\)|"
69+
r"get expected at least 1 argument, got 0")
6970
self.assertRaisesRegex(TypeError, msg, {}.get)
7071

7172
msg = r"expected 1 argument, got 0"
@@ -76,11 +77,13 @@ def test_varargs2min(self):
7677
self.assertRaisesRegex(TypeError, msg, getattr)
7778

7879
def test_varargs1max(self):
79-
msg = r"input expected at most 1 argument, got 2"
80+
msg = (r"input\(\) takes at most 1 argument \(2 given\)|"
81+
r"input expected at most 1 argument, got 2")
8082
self.assertRaisesRegex(TypeError, msg, input, 1, 2)
8183

8284
def test_varargs2max(self):
83-
msg = r"get expected at most 2 arguments, got 3"
85+
msg = (r"get\(\) takes at most 2 arguments \(3 given\)|"
86+
r"get expected at most 2 arguments, got 3")
8487
self.assertRaisesRegex(TypeError, msg, {}.get, 1, 2, 3)
8588

8689
def test_varargs1_kw(self):
@@ -96,7 +99,7 @@ def test_varargs3_kw(self):
9699
self.assertRaisesRegex(TypeError, msg, bool, x=2)
97100

98101
def test_varargs4_kw(self):
99-
msg = r"^list[.]index\(\) takes no keyword arguments$"
102+
msg = r"^(list[.])?index\(\) takes no keyword arguments$"
100103
self.assertRaisesRegex(TypeError, msg, [].index, x=2)
101104

102105
def test_varargs5_kw(self):

Lib/test/test_enum.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -2799,11 +2799,13 @@ class SecondFailedStrEnum(CustomStrEnum):
27992799
class ThirdFailedStrEnum(CustomStrEnum):
28002800
one = '1'
28012801
two = 2 # this will become '2'
2802-
with self.assertRaisesRegex(TypeError, '.encoding. must be str, not '):
2802+
with self.assertRaisesRegex(TypeError,
2803+
r"argument (2|'encoding') must be str, not "):
28032804
class ThirdFailedStrEnum(CustomStrEnum):
28042805
one = '1'
28052806
two = b'2', sys.getdefaultencoding
2806-
with self.assertRaisesRegex(TypeError, '.errors. must be str, not '):
2807+
with self.assertRaisesRegex(TypeError,
2808+
r"argument (3|'errors') must be str, not "):
28072809
class ThirdFailedStrEnum(CustomStrEnum):
28082810
one = '1'
28092811
two = b'2', 'ascii', 9

Lib/test/test_pyexpat.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -281,12 +281,10 @@ def test_legal(self):
281281
expat.ParserCreate(namespace_separator=' ')
282282

283283
def test_illegal(self):
284-
try:
284+
with self.assertRaisesRegex(TypeError,
285+
r"ParserCreate\(\) argument (2|'namespace_separator') "
286+
r"must be str or None, not int"):
285287
expat.ParserCreate(namespace_separator=42)
286-
self.fail()
287-
except TypeError as e:
288-
self.assertEqual(str(e),
289-
"ParserCreate() argument 'namespace_separator' must be str or None, not int")
290288

291289
try:
292290
expat.ParserCreate(namespace_separator='too long')

Modules/_localemodule.c

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ This software comes with no warranty. Use at your own risk.
1111

1212
#include "Python.h"
1313
#include "pycore_fileutils.h"
14+
#include "pycore_pymem.h" // _PyMem_Strdup
1415

1516
#include <stdio.h>
1617
#include <locale.h>

Modules/_sqlite/module.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ load_functools_lru_cache(PyObject *module)
244244
static PyMethodDef module_methods[] = {
245245
PYSQLITE_ADAPT_METHODDEF
246246
PYSQLITE_COMPLETE_STATEMENT_METHODDEF
247-
PYSQLITE_CONNECT_METHODDEF
247+
{"connect", _PyCFunction_CAST(pysqlite_connect), METH_FASTCALL|METH_KEYWORDS, pysqlite_connect__doc__},
248248
PYSQLITE_ENABLE_CALLBACK_TRACE_METHODDEF
249249
PYSQLITE_REGISTER_ADAPTER_METHODDEF
250250
PYSQLITE_REGISTER_CONVERTER_METHODDEF

Modules/_struct.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ class cache_struct_converter(CConverter):
108108
type = 'PyStructObject *'
109109
converter = 'cache_struct_converter'
110110
c_default = "NULL"
111+
broken_limited_capi = True
111112
112113
def parse_arg(self, argname, displayname):
113114
return """
@@ -120,7 +121,7 @@ class cache_struct_converter(CConverter):
120121
def cleanup(self):
121122
return "Py_XDECREF(%s);\n" % self.name
122123
[python start generated code]*/
123-
/*[python end generated code: output=da39a3ee5e6b4b0d input=d6746621c2fb1a7d]*/
124+
/*[python end generated code: output=da39a3ee5e6b4b0d input=14e83804f599ed8f]*/
124125

125126
static int cache_struct_converter(PyObject *, PyObject *, PyStructObject **);
126127

Modules/_tracemalloc.c

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "Python.h"
2+
#include "pycore_tracemalloc.h" // _PyTraceMalloc_IsTracing
23

34
#include "clinic/_tracemalloc.c.h"
45

Modules/clinic/_testclinic_limited.c.h

+2-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

PC/winreg.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ class DWORD_converter(unsigned_long_converter):
220220
class HKEY_converter(CConverter):
221221
type = 'HKEY'
222222
converter = 'clinic_HKEY_converter'
223+
broken_limited_capi = True
223224
224225
def parse_arg(self, argname, displayname):
225226
return """
@@ -249,7 +250,7 @@ class self_return_converter(CReturnConverter):
249250
data.return_conversion.append(
250251
'return_value = (PyObject *)_return_value;\n')
251252
[python start generated code]*/
252-
/*[python end generated code: output=da39a3ee5e6b4b0d input=17e645060c7b8ae1]*/
253+
/*[python end generated code: output=da39a3ee5e6b4b0d input=f8cb7034338aeaba]*/
253254

254255
#include "clinic/winreg.c.h"
255256

0 commit comments

Comments
 (0)