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
-------------------------------------------
@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
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
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))
__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):