Skip to content

Commit 720842a

Browse files
committed
bpo-45320 Remove deprecated inspect methods
1 parent f76889a commit 720842a

File tree

6 files changed

+48
-260
lines changed

6 files changed

+48
-260
lines changed

Doc/howto/clinic.rst

-3
Original file line numberDiff line numberDiff line change
@@ -567,9 +567,6 @@ expression. Currently the following are explicitly supported:
567567
* Simple symbolic constants like ``sys.maxsize``, which must
568568
start with the name of the module
569569

570-
In case you're curious, this is implemented in ``from_builtin()``
571-
in ``Lib/inspect.py``.
572-
573570
(In the future, this may need to get even more elaborate,
574571
to allow full expressions like ``CONSTANT - 1``.)
575572

Doc/library/inspect.rst

-47
Original file line numberDiff line numberDiff line change
@@ -935,26 +935,6 @@ Classes and functions
935935
times.
936936

937937

938-
.. function:: getargspec(func)
939-
940-
Get the names and default values of a Python function's parameters. A
941-
:term:`named tuple` ``ArgSpec(args, varargs, keywords, defaults)`` is
942-
returned. *args* is a list of the parameter names. *varargs* and *keywords*
943-
are the names of the ``*`` and ``**`` parameters or ``None``. *defaults* is a
944-
tuple of default argument values or ``None`` if there are no default
945-
arguments; if this tuple has *n* elements, they correspond to the last
946-
*n* elements listed in *args*.
947-
948-
.. deprecated:: 3.0
949-
Use :func:`getfullargspec` for an updated API that is usually a drop-in
950-
replacement, but also correctly handles function annotations and
951-
keyword-only parameters.
952-
953-
Alternatively, use :func:`signature` and
954-
:ref:`Signature Object <inspect-signature-object>`, which provide a
955-
more structured introspection API for callables.
956-
957-
958938
.. function:: getfullargspec(func)
959939

960940
Get the names and default values of a Python function's parameters. A
@@ -1015,33 +995,6 @@ Classes and functions
1015995
This function was inadvertently marked as deprecated in Python 3.5.
1016996

1017997

1018-
.. function:: formatargspec(args[, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, annotations[, formatarg, formatvarargs, formatvarkw, formatvalue, formatreturns, formatannotations]])
1019-
1020-
Format a pretty argument spec from the values returned by
1021-
:func:`getfullargspec`.
1022-
1023-
The first seven arguments are (``args``, ``varargs``, ``varkw``,
1024-
``defaults``, ``kwonlyargs``, ``kwonlydefaults``, ``annotations``).
1025-
1026-
The other six arguments are functions that are called to turn argument names,
1027-
``*`` argument name, ``**`` argument name, default values, return annotation
1028-
and individual annotations into strings, respectively.
1029-
1030-
For example:
1031-
1032-
>>> from inspect import formatargspec, getfullargspec
1033-
>>> def f(a: int, b: float):
1034-
... pass
1035-
...
1036-
>>> formatargspec(*getfullargspec(f))
1037-
'(a: int, b: float)'
1038-
1039-
.. deprecated:: 3.5
1040-
Use :func:`signature` and
1041-
:ref:`Signature Object <inspect-signature-object>`, which provide a
1042-
better introspecting API for callables.
1043-
1044-
1045998
.. function:: formatargvalues(args[, varargs, varkw, locals, formatarg, formatvarargs, formatvarkw, formatvalue])
1046999

10471000
Format a pretty argument spec from the four values returned by

Doc/whatsnew/3.11.rst

+19-3
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ Removed
348348
``SO_REUSEADDR`` in UDP.
349349
(Contributed by Hugo van Kemenade in :issue:`45129`.)
350350

351-
* Remove :meth:`__getitem__` methods of
351+
* Removed :meth:`__getitem__` methods of
352352
:class:`xml.dom.pulldom.DOMEventStream`, :class:`wsgiref.util.FileWrapper`
353353
and :class:`fileinput.FileInput`, deprecated since Python 3.9.
354354
(Contributed by Hugo van Kemenade in :issue:`45132`.)
@@ -387,7 +387,7 @@ Removed
387387
the ``l*gettext()`` functions.
388388
(Contributed by Dong-hee Na and Serhiy Storchaka in :issue:`44235`.)
389389

390-
* Remove from the :mod:`configparser` module:
390+
* Removed from the :mod:`configparser` module:
391391
the :class:`SafeConfigParser` class,
392392
the :attr:`filename` property of the :class:`ParsingError` class,
393393
the :meth:`readfp` method of the :class:`ConfigParser` class,
@@ -404,9 +404,25 @@ Removed
404404
generator-based coroutine objects in the debug mode.
405405
(Contributed by Illia Volochii in :issue:`43216`.)
406406

407-
* Remove the deprecated ``split()`` method of :class:`_tkinter.TkappType`.
407+
* Removed the deprecated ``split()`` method of :class:`_tkinter.TkappType`.
408408
(Contributed by Erlend E. Aasland in :issue:`38371`.)
409409

410+
* Removed from the :mod:`inspect` module:
411+
412+
* the ``getargspec`` function, deprecated since Python 3.0;
413+
use :func:`inspect.signature` or :func:`inspect.getfullargspec` instead.
414+
415+
* the ``formatargspec`` function, deprecated since Python 3.5;
416+
use the :func:`inspect.signature` function and :class:`Signature` object
417+
directly.
418+
419+
* the undocumented ``Signature.from_callable`` and ``Signature.from_function``
420+
functions, deprecated since Python 3.5; use the
421+
:meth:`Signature.from_callable() <inspect.Signature.from_callable>` method
422+
instead.
423+
424+
(Contributed by Hugo van Kemenade in :issue:`45320`.)
425+
410426

411427
Porting to Python 3.11
412428
======================

Lib/inspect.py

-113
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
import tokenize
4848
import token
4949
import types
50-
import warnings
5150
import functools
5251
import builtins
5352
from operator import attrgetter
@@ -1214,37 +1213,6 @@ def getargs(co):
12141213
varkw = co.co_varnames[nargs]
12151214
return Arguments(args + kwonlyargs, varargs, varkw)
12161215

1217-
ArgSpec = namedtuple('ArgSpec', 'args varargs keywords defaults')
1218-
1219-
def getargspec(func):
1220-
"""Get the names and default values of a function's parameters.
1221-
1222-
A tuple of four things is returned: (args, varargs, keywords, defaults).
1223-
'args' is a list of the argument names, including keyword-only argument names.
1224-
'varargs' and 'keywords' are the names of the * and ** parameters or None.
1225-
'defaults' is an n-tuple of the default values of the last n parameters.
1226-
1227-
This function is deprecated, as it does not support annotations or
1228-
keyword-only parameters and will raise ValueError if either is present
1229-
on the supplied callable.
1230-
1231-
For a more structured introspection API, use inspect.signature() instead.
1232-
1233-
Alternatively, use getfullargspec() for an API with a similar namedtuple
1234-
based interface, but full support for annotations and keyword-only
1235-
parameters.
1236-
1237-
Deprecated since Python 3.5, use `inspect.getfullargspec()`.
1238-
"""
1239-
warnings.warn("inspect.getargspec() is deprecated since Python 3.0, "
1240-
"use inspect.signature() or inspect.getfullargspec()",
1241-
DeprecationWarning, stacklevel=2)
1242-
args, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, ann = \
1243-
getfullargspec(func)
1244-
if kwonlyargs or ann:
1245-
raise ValueError("Function has keyword-only parameters or annotations"
1246-
", use inspect.signature() API which can support them")
1247-
return ArgSpec(args, varargs, varkw, defaults)
12481216

12491217
FullArgSpec = namedtuple('FullArgSpec',
12501218
'args, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, annotations')
@@ -1369,63 +1337,6 @@ def _formatannotation(annotation):
13691337
return formatannotation(annotation, module)
13701338
return _formatannotation
13711339

1372-
def formatargspec(args, varargs=None, varkw=None, defaults=None,
1373-
kwonlyargs=(), kwonlydefaults={}, annotations={},
1374-
formatarg=str,
1375-
formatvarargs=lambda name: '*' + name,
1376-
formatvarkw=lambda name: '**' + name,
1377-
formatvalue=lambda value: '=' + repr(value),
1378-
formatreturns=lambda text: ' -> ' + text,
1379-
formatannotation=formatannotation):
1380-
"""Format an argument spec from the values returned by getfullargspec.
1381-
1382-
The first seven arguments are (args, varargs, varkw, defaults,
1383-
kwonlyargs, kwonlydefaults, annotations). The other five arguments
1384-
are the corresponding optional formatting functions that are called to
1385-
turn names and values into strings. The last argument is an optional
1386-
function to format the sequence of arguments.
1387-
1388-
Deprecated since Python 3.5: use the `signature` function and `Signature`
1389-
objects.
1390-
"""
1391-
1392-
from warnings import warn
1393-
1394-
warn("`formatargspec` is deprecated since Python 3.5. Use `signature` and "
1395-
"the `Signature` object directly",
1396-
DeprecationWarning,
1397-
stacklevel=2)
1398-
1399-
def formatargandannotation(arg):
1400-
result = formatarg(arg)
1401-
if arg in annotations:
1402-
result += ': ' + formatannotation(annotations[arg])
1403-
return result
1404-
specs = []
1405-
if defaults:
1406-
firstdefault = len(args) - len(defaults)
1407-
for i, arg in enumerate(args):
1408-
spec = formatargandannotation(arg)
1409-
if defaults and i >= firstdefault:
1410-
spec = spec + formatvalue(defaults[i - firstdefault])
1411-
specs.append(spec)
1412-
if varargs is not None:
1413-
specs.append(formatvarargs(formatargandannotation(varargs)))
1414-
else:
1415-
if kwonlyargs:
1416-
specs.append('*')
1417-
if kwonlyargs:
1418-
for kwonlyarg in kwonlyargs:
1419-
spec = formatargandannotation(kwonlyarg)
1420-
if kwonlydefaults and kwonlyarg in kwonlydefaults:
1421-
spec += formatvalue(kwonlydefaults[kwonlyarg])
1422-
specs.append(spec)
1423-
if varkw is not None:
1424-
specs.append(formatvarkw(formatargandannotation(varkw)))
1425-
result = '(' + ', '.join(specs) + ')'
1426-
if 'return' in annotations:
1427-
result += formatreturns(formatannotation(annotations['return']))
1428-
return result
14291340

14301341
def formatargvalues(args, varargs, varkw, locals,
14311342
formatarg=str,
@@ -2932,30 +2843,6 @@ def __init__(self, parameters=None, *, return_annotation=_empty,
29322843
self._parameters = types.MappingProxyType(params)
29332844
self._return_annotation = return_annotation
29342845

2935-
@classmethod
2936-
def from_function(cls, func):
2937-
"""Constructs Signature for the given python function.
2938-
2939-
Deprecated since Python 3.5, use `Signature.from_callable()`.
2940-
"""
2941-
2942-
warnings.warn("inspect.Signature.from_function() is deprecated since "
2943-
"Python 3.5, use Signature.from_callable()",
2944-
DeprecationWarning, stacklevel=2)
2945-
return _signature_from_function(cls, func)
2946-
2947-
@classmethod
2948-
def from_builtin(cls, func):
2949-
"""Constructs Signature for the given builtin function.
2950-
2951-
Deprecated since Python 3.5, use `Signature.from_callable()`.
2952-
"""
2953-
2954-
warnings.warn("inspect.Signature.from_builtin() is deprecated since "
2955-
"Python 3.5, use Signature.from_callable()",
2956-
DeprecationWarning, stacklevel=2)
2957-
return _signature_from_builtin(cls, func)
2958-
29592846
@classmethod
29602847
def from_callable(cls, obj, *,
29612848
follow_wrapped=True, globals=None, locals=None, eval_str=False):

0 commit comments

Comments
 (0)