| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent a806e92 commit 1f885df
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,6 +24,7 @@ | |||
| 24 | 24 | from io import StringIO | |
| 25 | 25 | from collections import namedtuple | |
| 26 | 26 | from urllib.request import urlopen, urlcleanup | |
| 27 | + from test import support | ||
| 27 | 28 | from test.support import import_helper | |
| 28 | 29 | from test.support import os_helper | |
| 29 | 30 | from test.support.script_helper import (assert_python_ok, | |
@@ -1236,22 +1237,56 @@ def test_bound_builtin_classmethod_o(self): | |||
| 1236 | 1237 | self.assertEqual(self._get_summary_line(dict.__class_getitem__), | |
| 1237 | 1238 | "__class_getitem__(object, /) method of builtins.type instance") | |
| 1238 | 1239 | ||
| 1240 | + @support.cpython_only | ||
| 1239 | 1241 | def test_module_level_callable_unrepresentable_default(self): | |
| 1240 | - self.assertEqual(self._get_summary_line(getattr), | ||
| 1241 | - "getattr(...)") | ||
| 1242 | + import _testcapi | ||
| 1243 | + builtin = _testcapi.func_with_unrepresentable_signature | ||
| 1244 | + self.assertEqual(self._get_summary_line(builtin), | ||
| 1245 | + "func_with_unrepresentable_signature(a, b=<x>)") | ||
| 1242 | 1246 | ||
| 1247 | + @support.cpython_only | ||
| 1243 | 1248 | def test_builtin_staticmethod_unrepresentable_default(self): | |
| 1244 | 1249 | self.assertEqual(self._get_summary_line(str.maketrans), | |
| 1245 | 1250 | "maketrans(x, y=<unrepresentable>, z=<unrepresentable>, /)") | |
| 1251 | + import _testcapi | ||
| 1252 | + cls = _testcapi.DocStringUnrepresentableSignatureTest | ||
| 1253 | + self.assertEqual(self._get_summary_line(cls.staticmeth), | ||
| 1254 | + "staticmeth(a, b=<x>)") | ||
| 1246 | 1255 | ||
| 1256 | + @support.cpython_only | ||
| 1247 | 1257 | def test_unbound_builtin_method_unrepresentable_default(self): | |
| 1248 | 1258 | self.assertEqual(self._get_summary_line(dict.pop), | |
| 1249 | 1259 | "pop(self, key, default=<unrepresentable>, /)") | |
| 1260 | + import _testcapi | ||
| 1261 | + cls = _testcapi.DocStringUnrepresentableSignatureTest | ||
| 1262 | + self.assertEqual(self._get_summary_line(cls.meth), | ||
| 1263 | + "meth(self, /, a, b=<x>)") | ||
| 1250 | 1264 | ||
| 1265 | + @support.cpython_only | ||
| 1251 | 1266 | def test_bound_builtin_method_unrepresentable_default(self): | |
| 1252 | 1267 | self.assertEqual(self._get_summary_line({}.pop), | |
| 1253 | 1268 | "pop(key, default=<unrepresentable>, /) " | |
| 1254 | 1269 | "method of builtins.dict instance") | |
| 1270 | + import _testcapi | ||
| 1271 | + obj = _testcapi.DocStringUnrepresentableSignatureTest() | ||
| 1272 | + self.assertEqual(self._get_summary_line(obj.meth), | ||
| 1273 | + "meth(a, b=<x>) " | ||
| 1274 | + "method of _testcapi.DocStringUnrepresentableSignatureTest instance") | ||
| 1275 | + | ||
| 1276 | + @support.cpython_only | ||
| 1277 | + def test_unbound_builtin_classmethod_unrepresentable_default(self): | ||
| 1278 | + import _testcapi | ||
| 1279 | + cls = _testcapi.DocStringUnrepresentableSignatureTest | ||
| 1280 | + descr = cls.__dict__['classmeth'] | ||
| 1281 | + self.assertEqual(self._get_summary_line(descr), | ||
| 1282 | + "classmeth(type, /, a, b=<x>)") | ||
| 1283 | + | ||
| 1284 | + @support.cpython_only | ||
| 1285 | + def test_bound_builtin_classmethod_unrepresentable_default(self): | ||
| 1286 | + import _testcapi | ||
| 1287 | + cls = _testcapi.DocStringUnrepresentableSignatureTest | ||
| 1288 | + self.assertEqual(self._get_summary_line(cls.classmeth), | ||
| 1289 | + "classmeth(a, b=<x>) method of builtins.type instance") | ||
| 1255 | 1290 | ||
| 1256 | 1291 | def test_overridden_text_signature(self): | |
| 1257 | 1292 | class C: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -100,6 +100,13 @@ static PyMethodDef test_methods[] = { | |||
| 100 | 100 | {"test_with_docstring", | |
| 101 | 101 | test_with_docstring, METH_VARARGS, | |
| 102 | 102 | PyDoc_STR("This is a pretty normal docstring.")}, | |
| 103 | + {"func_with_unrepresentable_signature", | ||
| 104 | + (PyCFunction)test_with_docstring, METH_VARARGS, | ||
| 105 | + PyDoc_STR( | ||
| 106 | + "func_with_unrepresentable_signature($module, /, a, b=<x>)\n" | ||
| 107 | + "--\n\n" | ||
| 108 | + "This docstring has a signature with unrepresentable default." | ||
| 109 | + )}, | ||
| 103 | 110 | {NULL}, | |
| 104 | 111 | }; | |
| 105 | 112 | ||
@@ -140,6 +147,40 @@ static PyTypeObject DocStringNoSignatureTest = { | |||
| 140 | 147 | .tp_new = PyType_GenericNew, | |
| 141 | 148 | }; | |
| 142 | 149 | ||
| 150 | + static PyMethodDef DocStringUnrepresentableSignatureTest_methods[] = { | ||
| 151 | + {"meth", | ||
| 152 | + (PyCFunction)test_with_docstring, METH_VARARGS, | ||
| 153 | + PyDoc_STR( | ||
| 154 | + "meth($self, /, a, b=<x>)\n" | ||
| 155 | + "--\n\n" | ||
| 156 | + "This docstring has a signature with unrepresentable default." | ||
| 157 | + )}, | ||
| 158 | + {"classmeth", | ||
| 159 | + (PyCFunction)test_with_docstring, METH_VARARGS|METH_CLASS, | ||
| 160 | + PyDoc_STR( | ||
| 161 | + "classmeth($type, /, a, b=<x>)\n" | ||
| 162 | + "--\n\n" | ||
| 163 | + "This docstring has a signature with unrepresentable default." | ||
| 164 | + )}, | ||
| 165 | + {"staticmeth", | ||
| 166 | + (PyCFunction)test_with_docstring, METH_VARARGS|METH_STATIC, | ||
| 167 | + PyDoc_STR( | ||
| 168 | + "staticmeth(a, b=<x>)\n" | ||
| 169 | + "--\n\n" | ||
| 170 | + "This docstring has a signature with unrepresentable default." | ||
| 171 | + )}, | ||
| 172 | + {NULL}, | ||
| 173 | + }; | ||
| 174 | + | ||
| 175 | + static PyTypeObject DocStringUnrepresentableSignatureTest = { | ||
| 176 | + PyVarObject_HEAD_INIT(NULL, 0) | ||
| 177 | + .tp_name = "_testcapi.DocStringUnrepresentableSignatureTest", | ||
| 178 | + .tp_basicsize = sizeof(PyObject), | ||
| 179 | + .tp_flags = Py_TPFLAGS_DEFAULT, | ||
| 180 | + .tp_methods = DocStringUnrepresentableSignatureTest_methods, | ||
| 181 | + .tp_new = PyType_GenericNew, | ||
| 182 | + }; | ||
| 183 | + | ||
| 143 | 184 | int | |
| 144 | 185 | _PyTestCapi_Init_Docstring(PyObject *mod) | |
| 145 | 186 | { | |
@@ -149,5 +190,8 @@ _PyTestCapi_Init_Docstring(PyObject *mod) | |||
| 149 | 190 | if (PyModule_AddType(mod, &DocStringNoSignatureTest) < 0) { | |
| 150 | 191 | return -1; | |
| 151 | 192 | } | |
| 193 | + if (PyModule_AddType(mod, &DocStringUnrepresentableSignatureTest) < 0) { | ||
| 194 | + return -1; | ||
| 195 | + } | ||
| 152 | 196 | return 0; | |
| 153 | 197 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -420,6 +420,7 @@ Modules/_testcapi/buffer.c - testBufType - | |||
| 420 | 420 | Modules/_testcapi/code.c get_code_extra_index key - | |
| 421 | 421 | Modules/_testcapi/datetime.c - test_run_counter - | |
| 422 | 422 | Modules/_testcapi/docstring.c - DocStringNoSignatureTest - | |
| 423 | + Modules/_testcapi/docstring.c - DocStringUnrepresentableSignatureTest - | ||
| 423 | 424 | Modules/_testcapi/exceptions.c - PyRecursingInfinitelyError_Type - | |
| 424 | 425 | Modules/_testcapi/heaptype.c - _testcapimodule - | |
| 425 | 426 | Modules/_testcapi/mem.c - FmData - | |
| Back | FazBrowse Home | New Git URL |
0 commit comments