|
13 | 13 | import _pickle
|
14 | 14 | import pickle
|
15 | 15 | import shutil
|
| 16 | +import stat |
16 | 17 | import sys
|
| 18 | +import time |
17 | 19 | import types
|
18 | 20 | import tempfile
|
19 | 21 | import textwrap
|
|
22 | 24 | import unittest.mock
|
23 | 25 | import warnings
|
24 | 26 |
|
| 27 | + |
25 | 28 | try:
|
26 | 29 | from concurrent.futures import ThreadPoolExecutor
|
27 | 30 | except ImportError:
|
@@ -136,6 +139,14 @@ def gen_coroutine_function_example(self):
|
136 | 139 | yield
|
137 | 140 | return 'spam'
|
138 | 141 |
|
| 142 | +def meth_noargs(): pass |
| 143 | +def meth_o(object, /): pass |
| 144 | +def meth_self_noargs(self, /): pass |
| 145 | +def meth_self_o(self, object, /): pass |
| 146 | +def meth_type_noargs(type, /): pass |
| 147 | +def meth_type_o(type, object, /): pass |
| 148 | + |
| 149 | + |
139 | 150 | class TestPredicates(IsTestBase):
|
140 | 151 |
|
141 | 152 | def test_excluding_predicates(self):
|
@@ -1173,6 +1184,39 @@ def test_getfullargspec_builtin_func_no_signature(self):
|
1173 | 1184 | with self.assertRaises(TypeError):
|
1174 | 1185 | inspect.getfullargspec(builtin)
|
1175 | 1186 |
|
| 1187 | + cls = _testcapi.DocStringNoSignatureTest |
| 1188 | + obj = _testcapi.DocStringNoSignatureTest() |
| 1189 | + for builtin, template in [ |
| 1190 | + (_testcapi.docstring_no_signature_noargs, meth_noargs), |
| 1191 | + (_testcapi.docstring_no_signature_o, meth_o), |
| 1192 | + (cls.meth_noargs, meth_self_noargs), |
| 1193 | + (cls.meth_o, meth_self_o), |
| 1194 | + (obj.meth_noargs, meth_self_noargs), |
| 1195 | + (obj.meth_o, meth_self_o), |
| 1196 | + (cls.meth_noargs_class, meth_type_noargs), |
| 1197 | + (cls.meth_o_class, meth_type_o), |
| 1198 | + (cls.meth_noargs_static, meth_noargs), |
| 1199 | + (cls.meth_o_static, meth_o), |
| 1200 | + (cls.meth_noargs_coexist, meth_self_noargs), |
| 1201 | + (cls.meth_o_coexist, meth_self_o), |
| 1202 | + |
| 1203 | + (time.time, meth_noargs), |
| 1204 | + (stat.S_IMODE, meth_o), |
| 1205 | + (str.lower, meth_self_noargs), |
| 1206 | + (''.lower, meth_self_noargs), |
| 1207 | + (set.add, meth_self_o), |
| 1208 | + (set().add, meth_self_o), |
| 1209 | + (set.__contains__, meth_self_o), |
| 1210 | + (set().__contains__, meth_self_o), |
| 1211 | + (datetime.datetime.__dict__['utcnow'], meth_type_noargs), |
| 1212 | + (datetime.datetime.utcnow, meth_type_noargs), |
| 1213 | + (dict.__dict__['__class_getitem__'], meth_type_o), |
| 1214 | + (dict.__class_getitem__, meth_type_o), |
| 1215 | + ]: |
| 1216 | + with self.subTest(builtin): |
| 1217 | + self.assertEqual(inspect.getfullargspec(builtin), |
| 1218 | + inspect.getfullargspec(template)) |
| 1219 | + |
1176 | 1220 | def test_getfullargspec_definition_order_preserved_on_kwonly(self):
|
1177 | 1221 | for fn in signatures_with_lexicographic_keyword_only_parameters():
|
1178 | 1222 | signature = inspect.getfullargspec(fn)
|
@@ -2888,6 +2932,39 @@ def test_signature_on_builtins_no_signature(self):
|
2888 | 2932 | 'no signature found for builtin'):
|
2889 | 2933 | inspect.signature(str)
|
2890 | 2934 |
|
| 2935 | + cls = _testcapi.DocStringNoSignatureTest |
| 2936 | + obj = _testcapi.DocStringNoSignatureTest() |
| 2937 | + for builtin, template in [ |
| 2938 | + (_testcapi.docstring_no_signature_noargs, meth_noargs), |
| 2939 | + (_testcapi.docstring_no_signature_o, meth_o), |
| 2940 | + (cls.meth_noargs, meth_self_noargs), |
| 2941 | + (cls.meth_o, meth_self_o), |
| 2942 | + (obj.meth_noargs, meth_noargs), |
| 2943 | + (obj.meth_o, meth_o), |
| 2944 | + (cls.meth_noargs_class, meth_noargs), |
| 2945 | + (cls.meth_o_class, meth_o), |
| 2946 | + (cls.meth_noargs_static, meth_noargs), |
| 2947 | + (cls.meth_o_static, meth_o), |
| 2948 | + (cls.meth_noargs_coexist, meth_self_noargs), |
| 2949 | + (cls.meth_o_coexist, meth_self_o), |
| 2950 | + |
| 2951 | + (time.time, meth_noargs), |
| 2952 | + (stat.S_IMODE, meth_o), |
| 2953 | + (str.lower, meth_self_noargs), |
| 2954 | + (''.lower, meth_noargs), |
| 2955 | + (set.add, meth_self_o), |
| 2956 | + (set().add, meth_o), |
| 2957 | + (set.__contains__, meth_self_o), |
| 2958 | + (set().__contains__, meth_o), |
| 2959 | + (datetime.datetime.__dict__['utcnow'], meth_type_noargs), |
| 2960 | + (datetime.datetime.utcnow, meth_noargs), |
| 2961 | + (dict.__dict__['__class_getitem__'], meth_type_o), |
| 2962 | + (dict.__class_getitem__, meth_o), |
| 2963 | + ]: |
| 2964 | + with self.subTest(builtin): |
| 2965 | + self.assertEqual(inspect.signature(builtin), |
| 2966 | + inspect.signature(template)) |
| 2967 | + |
2891 | 2968 | def test_signature_on_non_function(self):
|
2892 | 2969 | with self.assertRaisesRegex(TypeError, 'is not a callable object'):
|
2893 | 2970 | inspect.signature(42)
|
|
0 commit comments