diff options
author | Yury Selivanov <yselivanov@sprymix.com> | 2015-05-21 03:07:02 (GMT) |
---|---|---|
committer | Yury Selivanov <yselivanov@sprymix.com> | 2015-05-21 03:07:02 (GMT) |
commit | 57c74fca025ccd80d9d5f7da2d296c30e34dfec9 (patch) | |
tree | 9f113dbe5209f1be7fca4d6aa0c32cfd91a2075d | |
parent | 45d61561541b35d9c8757b9cc87974edc73f8649 (diff) | |
download | cpython-57c74fca025ccd80d9d5f7da2d296c30e34dfec9.zip cpython-57c74fca025ccd80d9d5f7da2d296c30e34dfec9.tar.gz cpython-57c74fca025ccd80d9d5f7da2d296c30e34dfec9.tar.bz2 |
Issue 24248: Deprecate inspect.Signature.from_function and .from_builtin
-rw-r--r-- | Doc/whatsnew/3.5.rst | 5 | ||||
-rw-r--r-- | Lib/inspect.py | 6 | ||||
-rw-r--r-- | Lib/test/test_inspect.py | 14 | ||||
-rw-r--r-- | Misc/NEWS | 3 |
4 files changed, 16 insertions, 12 deletions
diff --git a/Doc/whatsnew/3.5.rst b/Doc/whatsnew/3.5.rst index 3761b89..c440e94 100644 --- a/Doc/whatsnew/3.5.rst +++ b/Doc/whatsnew/3.5.rst @@ -751,6 +751,11 @@ Deprecated Python modules, functions and methods left to a package. (Contributed by Vajrasky Kok and Berker Peksag in :issue:`1322`.) +* Previously undocumented ``from_function`` and ``from_builtin`` methods + of :class:`inspect.Signature` are deprecated. Use new + :meth:`inspect.Signature.from_callable` instead. (Contributed by Yury + Selivanov in :issue:`24248`.) + Deprecated functions and types of the C API ------------------------------------------- diff --git a/Lib/inspect.py b/Lib/inspect.py index 1e37fed..d17a498 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -2661,11 +2661,17 @@ class Signature: @classmethod def from_function(cls, func): """Constructs Signature for the given python function.""" + + warnings.warn("inspect.Signature.from_function() is deprecated, " + "use Signature.from_callable()", DeprecationWarning) return _signature_from_function(cls, func) @classmethod def from_builtin(cls, func): """Constructs Signature for the given builtin function.""" + + warnings.warn("inspect.Signature.from_builtin() is deprecated, " + "use Signature.from_callable()", DeprecationWarning) return _signature_from_builtin(cls, func) @classmethod diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index 8d11783..a4add38 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -1971,13 +1971,6 @@ class TestSignatureObject(unittest.TestCase): with self.assertRaisesRegex(TypeError, 'is not a callable object'): inspect.signature(42) - with self.assertRaisesRegex(TypeError, 'is not a Python function'): - inspect.Signature.from_function(42) - - def test_signature_from_builtin_errors(self): - with self.assertRaisesRegex(TypeError, 'is not a Python builtin'): - inspect.Signature.from_builtin(42) - def test_signature_from_functionlike_object(self): def func(a,b, *args, kwonly=True, kwonlyreq, **kwargs): pass @@ -1998,9 +1991,9 @@ class TestSignatureObject(unittest.TestCase): def __call__(self, *args, **kwargs): return self.func(*args, **kwargs) - sig_func = inspect.Signature.from_function(func) + sig_func = inspect.Signature.from_callable(func) - sig_funclike = inspect.Signature.from_function(funclike(func)) + sig_funclike = inspect.Signature.from_callable(funclike(func)) self.assertEqual(sig_funclike, sig_func) sig_funclike = inspect.signature(funclike(func)) @@ -2048,9 +2041,6 @@ class TestSignatureObject(unittest.TestCase): __defaults__ = func.__defaults__ __kwdefaults__ = func.__kwdefaults__ - with self.assertRaisesRegex(TypeError, 'is not a Python function'): - inspect.Signature.from_function(funclike) - self.assertEqual(str(inspect.signature(funclike)), '(marker)') def test_signature_on_method(self): @@ -183,6 +183,9 @@ Library inspect.Signature.from_callable() and inspect.signature(). Contributed by Yury Selivanov. +- Issue 24248: Deprecate inspect.Signature.from_function() and + inspect.Signature.from_builtin(). + Tests ----- |