Skip to content

gh-108494: Argument Clinic: fix support of Limited C API #108536

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions Lib/test/test_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ def test_varargs3(self):
self.assertRaisesRegex(TypeError, msg, int.from_bytes, b'a', 'little', False)

def test_varargs1min(self):
msg = r"get expected at least 1 argument, got 0"
msg = (r"get\(\) takes at least 1 argument \(0 given\)|"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PyArg_ParseTuple() produces slightly different error message.

r"get expected at least 1 argument, got 0")
self.assertRaisesRegex(TypeError, msg, {}.get)

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

def test_varargs1max(self):
msg = r"input expected at most 1 argument, got 2"
msg = (r"input\(\) takes at most 1 argument \(2 given\)|"
r"input expected at most 1 argument, got 2")
self.assertRaisesRegex(TypeError, msg, input, 1, 2)

def test_varargs2max(self):
msg = r"get expected at most 2 arguments, got 3"
msg = (r"get\(\) takes at most 2 arguments \(3 given\)|"
r"get expected at most 2 arguments, got 3")
self.assertRaisesRegex(TypeError, msg, {}.get, 1, 2, 3)

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

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

def test_varargs5_kw(self):
Expand Down
6 changes: 4 additions & 2 deletions Lib/test/test_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -2799,11 +2799,13 @@ class SecondFailedStrEnum(CustomStrEnum):
class ThirdFailedStrEnum(CustomStrEnum):
one = '1'
two = 2 # this will become '2'
with self.assertRaisesRegex(TypeError, '.encoding. must be str, not '):
with self.assertRaisesRegex(TypeError,
r"argument (2|'encoding') must be str, not "):
class ThirdFailedStrEnum(CustomStrEnum):
one = '1'
two = b'2', sys.getdefaultencoding
with self.assertRaisesRegex(TypeError, '.errors. must be str, not '):
with self.assertRaisesRegex(TypeError,
r"argument (3|'errors') must be str, not "):
class ThirdFailedStrEnum(CustomStrEnum):
one = '1'
two = b'2', 'ascii', 9
Expand Down
8 changes: 3 additions & 5 deletions Lib/test/test_pyexpat.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,12 +281,10 @@ def test_legal(self):
expat.ParserCreate(namespace_separator=' ')

def test_illegal(self):
try:
with self.assertRaisesRegex(TypeError,
r"ParserCreate\(\) argument (2|'namespace_separator') "
r"must be str or None, not int"):
expat.ParserCreate(namespace_separator=42)
self.fail()
except TypeError as e:
self.assertEqual(str(e),
"ParserCreate() argument 'namespace_separator' must be str or None, not int")

try:
expat.ParserCreate(namespace_separator='too long')
Expand Down
1 change: 1 addition & 0 deletions Modules/_localemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ This software comes with no warranty. Use at your own risk.

#include "Python.h"
#include "pycore_fileutils.h"
#include "pycore_pymem.h" // _PyMem_Strdup

#include <stdio.h>
#include <locale.h>
Expand Down
2 changes: 1 addition & 1 deletion Modules/_sqlite/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ load_functools_lru_cache(PyObject *module)
static PyMethodDef module_methods[] = {
PYSQLITE_ADAPT_METHODDEF
PYSQLITE_COMPLETE_STATEMENT_METHODDEF
PYSQLITE_CONNECT_METHODDEF
{"connect", _PyCFunction_CAST(pysqlite_connect), METH_FASTCALL|METH_KEYWORDS, pysqlite_connect__doc__},
PYSQLITE_ENABLE_CALLBACK_TRACE_METHODDEF
PYSQLITE_REGISTER_ADAPTER_METHODDEF
PYSQLITE_REGISTER_CONVERTER_METHODDEF
Expand Down
3 changes: 2 additions & 1 deletion Modules/_struct.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class cache_struct_converter(CConverter):
type = 'PyStructObject *'
converter = 'cache_struct_converter'
c_default = "NULL"
broken_limited_capi = True

def parse_arg(self, argname, displayname):
return """
Expand All @@ -120,7 +121,7 @@ class cache_struct_converter(CConverter):
def cleanup(self):
return "Py_XDECREF(%s);\n" % self.name
[python start generated code]*/
/*[python end generated code: output=da39a3ee5e6b4b0d input=d6746621c2fb1a7d]*/
/*[python end generated code: output=da39a3ee5e6b4b0d input=14e83804f599ed8f]*/

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

Expand Down
1 change: 1 addition & 0 deletions Modules/_tracemalloc.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "Python.h"
#include "pycore_tracemalloc.h" // _PyTraceMalloc_IsTracing

#include "clinic/_tracemalloc.c.h"

Expand Down
5 changes: 2 additions & 3 deletions Modules/clinic/_testclinic_limited.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion PC/winreg.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ class DWORD_converter(unsigned_long_converter):
class HKEY_converter(CConverter):
type = 'HKEY'
converter = 'clinic_HKEY_converter'
broken_limited_capi = True

def parse_arg(self, argname, displayname):
return """
Expand Down Expand Up @@ -249,7 +250,7 @@ class self_return_converter(CReturnConverter):
data.return_conversion.append(
'return_value = (PyObject *)_return_value;\n')
[python start generated code]*/
/*[python end generated code: output=da39a3ee5e6b4b0d input=17e645060c7b8ae1]*/
/*[python end generated code: output=da39a3ee5e6b4b0d input=f8cb7034338aeaba]*/

#include "clinic/winreg.c.h"

Expand Down
Loading