10000 Fix tests · python/cpython@a28c62e · GitHub
[go: up one dir, main page]

Skip to content

Commit a28c62e

Browse files
Fix tests
2 parents 803f991 + 5df8b0d commit a28c62e

File tree

8 files changed

+342
-324
lines changed

8 files changed

+342
-324
lines changed

Lib/test/test_clinic.py

Lines changed: 58 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2319,15 +2319,11 @@ class ClinicFunctionalTest(unittest.TestCase):
23192319
locals().update((name, getattr(ac_tester, name))
23202320
for name in dir(ac_tester) if name.startswith('test_'))
23212321

2322-
def check_depr_star(self, fn, *, fname, pnames, ok_args, fail_args):
2322+
def check_depr_star(self, fn, *, regex, ok_args, fail_args):
23232323
for args, kwds in ok_args:
23242324
fn(*args, **kwds)
2325-
regex = (
2326-
f"Passing.*positional argument.*to {fname}.*is deprecated. "
2327-
f"Parameter.*{pnames} will become.*keyword-only parameter.*in Python 3.14"
2328-
)
23292325
for args, kwds in fail_args:
2330-
with self.assertWarnsRegex(DeprecationWarning, regex) as cm:
2326+
with self.assertWarnsRegex(DeprecationWarning, re.escape(regex)) as cm:
23312327
fn(*args, **kwds)
23322328
self.assertTrue(cm.filename.endswith("test_clinic.py"), cm.filename)
23332329
fn(*args, **kwds) # No warning raised second time
@@ -2797,10 +2793,13 @@ def test_cloned_func_with_converter_exception_message(self):
27972793
self.assertEqual(func(), name)
27982794

27992795
def test_depr_star_pos0_len1(self):
2800-
fn = ac_tester.deprecate_positional_pos0_len1
2796+
fn = ac_tester.depr_star_pos0_len1
28012797
self.check_depr_star(fn,
2802-
fname="deprecate_positional_pos0_len1",
2803-
pnames="'a'",
2798+
regex=(
2799+
"Passing positional arguments to depr_star_pos0_len1() "
2800+
"is deprecated. Parameter 'a' will become a keyword-only "
2801+
"parameter in Python 3.14"
2802+
),
28042803
ok_args=(
28052804
((), {"a": None}),
28062805
),
@@ -2810,10 +2809,13 @@ def test_depr_star_pos0_len1(self):
28102809
)
28112810

28122811
def test_depr_star_pos0_len2(self):
2813-
fn = ac_tester.deprecate_positional_pos0_len2
2812+
fn = ac_tester.depr_star_pos0_len2
28142813
self.check_depr_star(fn,
2815-
fname="deprecate_positional_pos0_len2",
2816-
pnames="'a' and 'b'",
2814+
regex=(
2815+
"Passing positional arguments to depr_star_pos0_len2() "
2816+
"is deprecated. Parameters 'a' and 'b' will become "
2817+
"keyword-only parameters in Python 3.14"
2818+
),
28172819
ok_args=(
28182820
((), {"a": None, "b": None}),
28192821
),
@@ -2823,10 +2825,13 @@ def test_depr_star_pos0_len2(self):
28232825
)
28242826

28252827
def test_depr_star_pos0_len3_with_kwd(self):
2826-
fn = ac_tester.deprecate_positional_pos0_len3_with_kwd
2828+
fn = ac_tester.depr_star_pos0_len3_with_kwd
28272829
self.check_depr_star(fn,
2828-
fname="deprecate_positional_pos0_len3_with_kwd",
2829-
pnames="'a', 'b' and 'c'",
2830+
regex=(
2831+
"Passing positional arguments to depr_star_pos0_len3_with_kwd() "
2832+
"is deprecated. Parameters 'a', 'b' and 'c' will become "
2833+
"keyword-only parameters in Python 3.14"
2834+
),
28302835
ok_args=(
28312836
((), {"a": None, "b": None, "c": None, "d": None}),
28322837
),
@@ -2837,11 +2842,14 @@ def test_depr_star_pos0_len3_with_kwd(self):
28372842
)
28382843
)
28392844

2840-
def test_depr_star_pos1_len1_optional(self):
2841-
fn = ac_tester.deprecate_positional_pos1_len1_optional
2845+
def test_depr_star_pos1_len1_opt(self):
2846+
fn = ac_tester.depr_star_pos1_len1_opt
28422847
self.check_depr_star(fn,
2843-
fname="deprecate_positional_pos1_len1_optional",
2844-
pnames="'b'",
2848+
regex=(
2849+
"Passing 2 positional arguments to depr_star_pos1_len1_opt() "
2850+
"is deprecated. Parameter 'b' will become a keyword-only "
2851+
"parameter in Python 3.14"
2852+
),
28452853
ok_args=(
28462854
((), {"a": None, "b": None}),
28472855
((None,), {}),
@@ -2853,10 +2861,13 @@ def test_depr_star_pos1_len1_optional(self):
28532861
)
28542862

28552863
def test_depr_star_pos1_len1(self):
2856-
fn = ac_tester.deprecate_positional_pos1_len1
2864+
fn = ac_tester.depr_star_pos1_len1
28572865
self.check_depr_star(fn,
2858-
fname="deprecate_positional_pos1_len1",
2859-
pnames="'b'",
2866+
regex=(
2867+
"Passing 2 positional arguments to depr_star_pos1_len1() is "
2868+
"deprecated. Parameter 'b' will become a keyword-only "
2869+
"parameter in Python 3.14"
2870+
),
28602871
ok_args=(
28612872
((), {"a": None, "b": None}),
28622873
((None,), {"b": None}),
@@ -2867,10 +2878,13 @@ def test_depr_star_pos1_len1(self):
28672878
)
28682879

28692880
def test_depr_star_pos1_len2_with_kwd(self):
2870-
fn = ac_tester.deprecate_positional_pos1_len2_with_kwd
2881+
fn = ac_tester.depr_star_pos1_len2_with_kwd
28712882
self.check_depr_star(fn,
2872-
fname="deprecate_positional_pos1_len2_with_kwd",
2873-
pnames="'b' and 'c'",
2883+
regex=(
2884+
"Passing more than 1 positional argument to "
2885+
"depr_star_pos1_len2_with_kwd() is deprecated. Parameters 'b' "
2886+
"and 'c' will become keyword-only parameters in Python 3.14"
2887+
),
28742888
ok_args=(
28752889
((), {"a": None, "b": None, "c": None, "d": None}),
28762890
((None,), {"b": None, "c": None, "d": None}),
@@ -2882,10 +2896,13 @@ def test_depr_star_pos1_len2_with_kwd(self):
28822896
)
28832897

28842898
def test_depr_star_pos2_len1(self):
2885-
fn = ac_tester.deprecate_positional_pos2_len1
2899+
fn = ac_tester.depr_star_pos2_len1
28862900
self.check_depr_star(fn,
2887-
fname="deprecate_positional_pos2_len1",
2888-
pnames="'c'",
2901+
regex=(
2902+
"Passing 3 positional arguments to depr_star_pos2_len1() is "
2903+
"deprecated. Parameter 'c' will become a keyword-only "
2904+
"parameter in Python 3.14"
2905+
),
28892906
ok_args=(
28902907
((), {"a": None, "b": None, "c": None}),
28912908
((None,), {"b": None, "c": None}),
@@ -2897,10 +2914,13 @@ def test_depr_star_pos2_len1(self):
28972914
)
28982915

28992916
def test_depr_star_pos2_len2(self):
2900-
fn = ac_tester.deprecate_positional_pos2_len2
2917+
fn = ac_tester.depr_star_pos2_len2
29012918
self.check_depr_star(fn,
2902-
fname="deprecate_positional_pos2_len2",
2903-
pnames="'c' and 'd'",
2919+
regex=(
2920+ EF5E
"Passing more than 2 positional arguments to "
2921+
"depr_star_pos2_len2() is deprecated. Parameters 'c' and 'd' "
2922+
"will become keyword-only parameters in Python 3.14"
2923+
),
29042924
ok_args=(
29052925
((), {"a": None, "b": None, "c": None, "d": None}),
29062926
((None,), {"b": None, "c": None, "d": None}),
@@ -2912,11 +2932,14 @@ def test_depr_star_pos2_len2(self):
29122932
)
29132933
)
29142934

2915-
def test_depr_star_pos2_len3_with_kwd(self):
2916-
fn = ac_tester.deprecate_positional_pos2_len3_with_kwd
2935+
def test_depr_star_pos2_len2_with_kwd(self):
2936+
fn = ac_tester.depr_star_pos2_len2_with_kwd
29172937
self.check_depr_star(fn,
2918-
fname="deprecate_positional_pos2_len3_with_kwd",
2919-
pnames="'c' and 'd'",
2938+
regex=(
2939+
"Passing more than 2 positional arguments to "
2940+
"depr_star_pos2_len2_with_kwd() is deprecated. Parameters 'c' "
2941+
"and 'd' will become keyword-only parameters in Python 3.14"
2942+
),
29202943
ok_args=(
29212944
((), {"a": None, "b": None, "c": None, "d": None, "e": None}),
29222945
((None,), {"b": None, "c": None, "d": None, "e": None}),
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add docstrings for :func:`ctypes.pointer` and :func:`ctypes.POINTER`.

Modules/_ctypes/callproc.c

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@
5454
5555
*/
5656

57+
/*[clinic input]
58+
module _ctypes
59+
[clinic start generated code]*/
60+
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=476a19c49b31a75c]*/
61+
5762
#ifndef Py_BUILD_CORE_BUILTIN
5863
# define Py_BUILD_CORE_MODULE 1
5964
#endif
@@ -98,6 +103,7 @@
98103

99104
#include "pycore_runtime.h" // _PyRuntime
100105
#include "pycore_global_objects.h" // _Py_ID()
106+
#include "clinic/callproc.c.h"
101107

102108
#define CTYPES_CAPSULE_NAME_PYMEM "_ctypes pymem"
103109

@@ -1893,8 +1899,22 @@ unpickle(PyObject *self, PyObject *args)
18931899
return NULL;
18941900
}
18951901

1902+
/*[clinic input]
1903+
_ctypes.POINTER as create_pointer_type
1904+
1905+
type as cls: object
1906+
A ctypes type.
1907+
/
1908+
1909+
Create and return a new ctypes pointer type.
1910+
1911+
Pointer types are cached and reused internally,
1912+
so calling this function repeatedly is cheap.
1913+
[clinic start generated code]*/
1914+
18961915
static PyObject *
1897-
POINTER(PyObject *self, PyObject *cls)
1916+
create_pointer_type(PyObject *module, PyObject *cls)
1917+
/*[clinic end generated code: output=98c3547ab6f4f40b input=3b81cff5ff9b9d5b]*/
18981918
{
18991919
PyObject *result;
19001920
PyTypeObject *typ;
@@ -1944,8 +1964,22 @@ POINTER(PyObject *self, PyObject *cls)
19441964
return result;
19451965
}
19461966

1967+
/*[clinic input]
1968+
_ctypes.pointer as create_pointer_inst
1969+
1970+
obj as arg: object
1971+
/
1972+
1973+
Create a new pointer instance, pointing to 'obj'.
1974+
1975+
The returned object is of the type POINTER(type(obj)). Note that if you
1976+
just want to pass a pointer to an object to a foreign function call, you
1977+
should use byref(obj) which is much faster.
1978+
[clinic start generated code]*/
1979+
19471980
static PyObject *
1948-
pointer(PyObject *self, PyObject *arg)
1981+
create_pointer_inst(PyObject *module, PyObject *arg)
1982+
/*[clinic end generated code: output=3b543bc9f0de2180 input=713685fdb4d9bc27]*/
19491983
{
19501984
PyObject *result;
19511985
PyObject *typ;
@@ -1957,7 +1991,7 @@ pointer(PyObject *self, PyObject *arg)
19571991
else if (PyErr_Occurred()) {
19581992
return NULL;
19591993
}
1960-
typ = POINTER(NULL, (PyObject *)Py_TYPE(arg));
1994+
typ = create_pointer_type(NULL, (PyObject *)Py_TYPE(arg));
19611995
if (typ == NULL)
19621996
return NULL;
19631997
result = PyObject_CallOneArg(typ, arg);
@@ -1997,8 +2031,8 @@ buffer_info(PyObject *self, PyObject *arg)
19972031
PyMethodDef _ctypes_module_methods[] = {
19982032
{"get_errno", get_errno, METH_NOARGS},
19992033
{"set_errno", set_errno, METH_VARARGS},
2000-
{"POINTER", POINTER, METH_O },
2001-
{"pointer", pointer, METH_O },
2034+
CREATE_POINTER_TYPE_METHODDEF
2035+
CREATE_POINTER_INST_METHODDEF
20022036
{"_unpickle", unpickle, METH_VARARGS },
20032037
{"buffer_info", buffer_info, METH_O, "Return buffer interface information"},
20042038
{"resize", resize, METH_VARARGS, "Resize the memory buffer of a ctypes instance"},

Modules/_ctypes/clinic/callproc.c.h

Lines changed: 38 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
0