mirror of
https://github.com/python/cpython.git
synced 2025-11-02 19:12:55 +00:00
Actually run the builtins Argument Clinic test
This commit is contained in:
parent
3f103462fb
commit
9c680b0728
1 changed files with 58 additions and 53 deletions
|
|
@ -1660,56 +1660,6 @@ class MyParameter(inspect.Parameter):
|
||||||
# used in test_signature_object_pickle
|
# used in test_signature_object_pickle
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@cpython_only
|
|
||||||
@unittest.skipIf(MISSING_C_DOCSTRINGS,
|
|
||||||
"Signature information for builtins requires docstrings")
|
|
||||||
def test_builtins_have_signatures(self):
|
|
||||||
# This checks all builtin callables in CPython have signatures
|
|
||||||
# A few have signatures Signature can't yet handle, so we skip those
|
|
||||||
# since they will have to wait until PEP 457 adds the required
|
|
||||||
# introspection support to the inspect module
|
|
||||||
# Some others also haven't been converted yet for various other
|
|
||||||
# reasons, so we also skip those for the time being, but design
|
|
||||||
# the test to fail in order to indicate when it needs to be
|
|
||||||
# updated.
|
|
||||||
no_signature = set()
|
|
||||||
# These need PEP 457 groups
|
|
||||||
needs_groups = ["range", "slice", "dir", "getattr",
|
|
||||||
"next", "iter", "vars"]
|
|
||||||
no_signature |= needs_groups
|
|
||||||
# These need PEP 457 groups or a signature change to accept None
|
|
||||||
needs_semantic_update = ["round"]
|
|
||||||
no_signature |= needs_semantic_update
|
|
||||||
# These need *args support in Argument Clinic
|
|
||||||
needs_varargs = ["min", "max", "print", "__build_class__"]
|
|
||||||
no_signature |= needs_varargs
|
|
||||||
# These simply weren't covered in the initial AC conversion
|
|
||||||
# for builtin callables
|
|
||||||
not_converted_yet = ["open", "__import__"]
|
|
||||||
no_signature |= not_converted_yet
|
|
||||||
# These builtin types are expected to provide introspection info
|
|
||||||
types_with_signatures = set()
|
|
||||||
# Check the signatures we expect to be there
|
|
||||||
ns = vars(builtins)
|
|
||||||
for name, obj in sorted(ns.items()):
|
|
||||||
if not callable(obj):
|
|
||||||
continue
|
|
||||||
# The builtin types haven't been converted to AC yet
|
|
||||||
if isinstance(obj, type) and (name not in types_with_signatures):
|
|
||||||
# Note that this also skips all the exception types
|
|
||||||
no_signature.append(name)
|
|
||||||
if (name in no_signature):
|
|
||||||
# Not yet converted
|
|
||||||
continue
|
|
||||||
with self.subTest(builtin=name):
|
|
||||||
self.assertIsNotNone(inspect.signature(obj))
|
|
||||||
# Check callables that haven't been converted don't claim a signature
|
|
||||||
# This ensures this test will start failing as more signatures are
|
|
||||||
# added, so the affected items can be moved into the scope of the
|
|
||||||
# regression test above
|
|
||||||
for name in no_signature:
|
|
||||||
with self.subTest(builtin=name):
|
|
||||||
self.assertIsNone(ns[name].__text_signature__)
|
|
||||||
|
|
||||||
|
|
||||||
class TestSignatureObject(unittest.TestCase):
|
class TestSignatureObject(unittest.TestCase):
|
||||||
|
|
@ -1914,7 +1864,6 @@ class TestSignatureObject(unittest.TestCase):
|
||||||
test_unbound_method(dict.__delitem__)
|
test_unbound_method(dict.__delitem__)
|
||||||
test_unbound_method(property.__delete__)
|
test_unbound_method(property.__delete__)
|
||||||
|
|
||||||
|
|
||||||
@cpython_only
|
@cpython_only
|
||||||
@unittest.skipIf(MISSING_C_DOCSTRINGS,
|
@unittest.skipIf(MISSING_C_DOCSTRINGS,
|
||||||
"Signature information for builtins requires docstrings")
|
"Signature information for builtins requires docstrings")
|
||||||
|
|
@ -3182,6 +3131,61 @@ class TestSignaturePrivateHelpers(unittest.TestCase):
|
||||||
None,
|
None,
|
||||||
None)
|
None)
|
||||||
|
|
||||||
|
class TestSignatureDefinitions(unittest.TestCase):
|
||||||
|
# This test case provides a home for checking that particular APIs
|
||||||
|
# have signatures available for introspection
|
||||||
|
|
||||||
|
@cpython_only
|
||||||
|
@unittest.skipIf(MISSING_C_DOCSTRINGS,
|
||||||
|
"Signature information for builtins requires docstrings")
|
||||||
|
def test_builtins_have_signatures(self):
|
||||||
|
# This checks all builtin callables in CPython have signatures
|
||||||
|
# A few have signatures Signature can't yet handle, so we skip those
|
||||||
|
# since they will have to wait until PEP 457 adds the required
|
||||||
|
# introspection support to the inspect module
|
||||||
|
# Some others also haven't been converted yet for various other
|
||||||
|
# reasons, so we also skip those for the time being, but design
|
||||||
|
# the test to fail in order to indicate when it needs to be
|
||||||
|
# updated.
|
||||||
|
no_signature = set()
|
||||||
|
# These need PEP 457 groups
|
||||||
|
needs_groups = {"range", "slice", "dir", "getattr",
|
||||||
|
"next", "iter", "vars"}
|
||||||
|
no_signature |= needs_groups
|
||||||
|
# These need PEP 457 groups or a signature change to accept None
|
||||||
|
needs_semantic_update = {"round"}
|
||||||
|
no_signature |= needs_semantic_update
|
||||||
|
# These need *args support in Argument Clinic
|
||||||
|
needs_varargs = {"min", "max", "print", "__build_class__"}
|
||||||
|
no_signature |= needs_varargs
|
||||||
|
# These simply weren't covered in the initial AC conversion
|
||||||
|
# for builtin callables
|
||||||
|
not_converted_yet = {"open", "__import__"}
|
||||||
|
no_signature |= not_converted_yet
|
||||||
|
# These builtin types are expected to provide introspection info
|
||||||
|
types_with_signatures = set()
|
||||||
|
# Check the signatures we expect to be there
|
||||||
|
ns = vars(builtins)
|
||||||
|
for name, obj in sorted(ns.items()):
|
||||||
|
if not callable(obj):
|
||||||
|
continue
|
||||||
|
# The builtin types haven't been converted to AC yet
|
||||||
|
if isinstance(obj, type) and (name not in types_with_signatures):
|
||||||
|
# Note that this also skips all the exception types
|
||||||
|
no_signature.add(name)
|
||||||
|
if (name in no_signature):
|
||||||
|
# Not yet converted
|
||||||
|
continue
|
||||||
|
with self.subTest(builtin=name):
|
||||||
|
self.assertIsNotNone(inspect.signature(obj))
|
||||||
|
# Check callables that haven't been converted don't claim a signature
|
||||||
|
# This ensures this test will start failing as more signatures are
|
||||||
|
# added, so the affected items can be moved into the scope of the
|
||||||
|
# regression test above
|
||||||
|
for name in no_signature:
|
||||||
|
with self.subTest(builtin=name):
|
||||||
|
self.assertIsNone(obj.__text_signature__)
|
||||||
|
|
||||||
|
|
||||||
class TestUnwrap(unittest.TestCase):
|
class TestUnwrap(unittest.TestCase):
|
||||||
|
|
||||||
|
|
@ -3323,8 +3327,9 @@ def test_main():
|
||||||
TestGetcallargsFunctions, TestGetcallargsMethods,
|
TestGetcallargsFunctions, TestGetcallargsMethods,
|
||||||
TestGetcallargsUnboundMethods, TestGetattrStatic, TestGetGeneratorState,
|
TestGetcallargsUnboundMethods, TestGetattrStatic, TestGetGeneratorState,
|
||||||
TestNoEOL, TestSignatureObject, TestSignatureBind, TestParameterObject,
|
TestNoEOL, TestSignatureObject, TestSignatureBind, TestParameterObject,
|
||||||
TestBoundArguments, TestSignaturePrivateHelpers, TestGetClosureVars,
|
TestBoundArguments, TestSignaturePrivateHelpers,
|
||||||
TestUnwrap, TestMain, TestReload
|
TestSignatureDefinitions,
|
||||||
|
TestGetClosureVars, TestUnwrap, TestMain, TestReload
|
||||||
)
|
)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue