]> granicus.if.org Git - python/commitdiff
Issue 24248: Deprecate inspect.Signature.from_function and .from_builtin
authorYury Selivanov <yselivanov@sprymix.com>
Thu, 21 May 2015 03:07:02 +0000 (23:07 -0400)
committerYury Selivanov <yselivanov@sprymix.com>
Thu, 21 May 2015 03:07:02 +0000 (23:07 -0400)
Doc/whatsnew/3.5.rst
Lib/inspect.py
Lib/test/test_inspect.py
Misc/NEWS

index 3761b89e623277ea5daee40c84676e71ec0ea593..c440e946ab96f422582585803f480f03847bc286 100644 (file)
@@ -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
 -------------------------------------------
 
index 1e37fed029b8b038a3505c1fd42f7ed3df7fe2ad..d17a498a37e7bff611bbd4cac38aa0038dcecc55 100644 (file)
@@ -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
index 8d1178314af949dc8f902a8facf6a65f2a1296be..a4add382528f989afb1c7554916cec215ecb8512 100644 (file)
@@ -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):
index fe83306ec1df27bc22377e3867a7f5d360534cc9..5838a63046b477a8faee3a5014a4d04cbad18e73 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -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
 -----