Skip to content

Commit c8348fb

Browse files
bpo-33594: Add deprecation info in inspect.py module (GH-7036)
(cherry picked from commit ded87d8) Co-authored-by: Matthias Bussonnier <bussonniermatthias@gmail.com>
1 parent 0f2fc8b commit c8348fb

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

Lib/inspect.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,8 +1070,10 @@ def getargspec(func):
10701070
Alternatively, use getfullargspec() for an API with a similar namedtuple
10711071
based interface, but full support for annotations and keyword-only
10721072
parameters.
1073+
1074+
Deprecated since Python 3.5, use `inspect.getfullargspec()`.
10731075
"""
1074-
warnings.warn("inspect.getargspec() is deprecated, "
1076+
warnings.warn("inspect.getargspec() is deprecated since Python 3.0, "
10751077
"use inspect.signature() or inspect.getfullargspec()",
10761078
DeprecationWarning, stacklevel=2)
10771079
args, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, ann = \
@@ -2802,19 +2804,25 @@ def __init__(self, parameters=None, *, return_annotation=_empty,
28022804

28032805
@classmethod
28042806
def from_function(cls, func):
2805-
"""Constructs Signature for the given python function."""
2807+
"""Constructs Signature for the given python function.
2808+
2809+
Deprecated since Python 3.5, use `Signature.from_callable()`.
2810+
"""
28062811

2807-
warnings.warn("inspect.Signature.from_function() is deprecated, "
2808-
"use Signature.from_callable()",
2812+
warnings.warn("inspect.Signature.from_function() is deprecated since "
2813+
"Python 3.5, use Signature.from_callable()",
28092814
DeprecationWarning, stacklevel=2)
28102815
return _signature_from_function(cls, func)
28112816

28122817
@classmethod
28132818
def from_builtin(cls, func):
2814-
"""Constructs Signature for the given builtin function."""
2819+
"""Constructs Signature for the given builtin function.
2820+
2821+
Deprecated since Python 3.5, use `Signature.from_callable()`.
2822+
"""
28152823

2816-
warnings.warn("inspect.Signature.from_builtin() is deprecated, "
2817-
"use Signature.from_callable()",
2824+
warnings.warn("inspect.Signature.from_builtin() is deprecated since "
2825+
"Python 3.5, use Signature.from_callable()",
28182826
DeprecationWarning, stacklevel=2)
28192827
return _signature_from_builtin(cls, func)
28202828

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Document ``getargspec``, ``from_function`` and ``from_builtin`` as
2+
deprecated in their respective docstring, and include version since
3+
deprecation in DeprecationWarning message.

0 commit comments

Comments
 (0)