GeezerVison is showing github.com — bpo-45320: Remove long-deprecated inspect methods (GH-28618) · python/cpython@d89fb9a
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: Doc/howto/clinic.rst -3Lines changed: 0 additions & 3 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -567,9 +567,6 @@ expression. Currently the following are explicitly supported: | 567 | 567 | * Simple symbolic constants like ``sys.maxsize``, which must | 568 | 568 | start with the name of the module | 569 | 569 |
| 570 | | -In case you're curious, this is implemented in ``from_builtin()`` | 571 | | -in ``Lib/inspect.py``. | 572 | | - | 573 | 570 | (In the future, this may need to get even more elaborate, | 574 | 571 | to allow full expressions like ``CONSTANT - 1``.) | 575 | 572 |
| |
Collapse file Copy file name to clipboardExpand all lines: Doc/library/inspect.rst -47Lines changed: 0 additions & 47 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -935,26 +935,6 @@ Classes and functions | 935 | 935 | times. | 936 | 936 |
| 937 | 937 |
| 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 | | - | 958 | 938 | .. function:: getfullargspec(func) | 959 | 939 |
| 960 | 940 | Get the names and default values of a Python function's parameters. A | @@ -1015,33 +995,6 @@ Classes and functions | 1015 | 995 | This function was inadvertently marked as deprecated in Python 3.5. | 1016 | 996 |
| 1017 | 997 |
| 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 | | - | 1045 | 998 | .. function:: formatargvalues(args[, varargs, varkw, locals, formatarg, formatvarargs, formatvarkw, formatvalue]) | 1046 | 999 |
| 1047 | 1000 | Format a pretty argument spec from the four values returned by | |
Collapse file Copy file name to clipboardExpand all lines: Doc/whatsnew/3.11.rst +19-3Lines changed: 19 additions & 3 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -363,7 +363,7 @@ Removed | 363 | 363 | ``SO_REUSEADDR`` in UDP. | 364 | 364 | (Contributed by Hugo van Kemenade in :issue:`45129`.) | 365 | 365 |
| 366 | | -* Remove :meth:`__getitem__` methods of | | 366 | +* Removed :meth:`__getitem__` methods of | 367 | 367 | :class:`xml.dom.pulldom.DOMEventStream`, :class:`wsgiref.util.FileWrapper` | 368 | 368 | and :class:`fileinput.FileInput`, deprecated since Python 3.9. | 369 | 369 | (Contributed by Hugo van Kemenade in :issue:`45132`.) | @@ -402,7 +402,7 @@ Removed | 402 | 402 | the ``l*gettext()`` functions. | 403 | 403 | (Contributed by Dong-hee Na and Serhiy Storchaka in :issue:`44235`.) | 404 | 404 |
| 405 | | -* Remove from the :mod:`configparser` module: | | 405 | +* Removed from the :mod:`configparser` module: | 406 | 406 | the :class:`SafeConfigParser` class, | 407 | 407 | the :attr:`filename` property of the :class:`ParsingError` class, | 408 | 408 | the :meth:`readfp` method of the :class:`ConfigParser` class, | @@ -419,9 +419,25 @@ Removed | 419 | 419 | generator-based coroutine objects in the debug mode. | 420 | 420 | (Contributed by Illia Volochii in :issue:`43216`.) | 421 | 421 |
| 422 | | -* Remove the deprecated ``split()`` method of :class:`_tkinter.TkappType`. | | 422 | +* Removed the deprecated ``split()`` method of :class:`_tkinter.TkappType`. | 423 | 423 | (Contributed by Erlend E. Aasland in :issue:`38371`.) | 424 | 424 |
| | 425 | +* Removed from the :mod:`inspect` module: | | 426 | + | | 427 | + * the ``getargspec`` function, deprecated since Python 3.0; | | 428 | + use :func:`inspect.signature` or :func:`inspect.getfullargspec` instead. | | 429 | + | | 430 | + * the ``formatargspec`` function, deprecated since Python 3.5; | | 431 | + use the :func:`inspect.signature` function and :class:`Signature` object | | 432 | + directly. | | 433 | + | | 434 | + * the undocumented ``Signature.from_callable`` and ``Signature.from_function`` | | 435 | + functions, deprecated since Python 3.5; use the | | 436 | + :meth:`Signature.from_callable() <inspect.Signature.from_callable>` method | | 437 | + instead. | | 438 | + | | 439 | + (Contributed by Hugo van Kemenade in :issue:`45320`.) | | 440 | + | 425 | 441 |
| 426 | 442 | Porting to Python 3.11 | 427 | 443 | ====================== | |
Collapse file Copy file name to clipboardExpand all lines: Lib/inspect.py -113Lines changed: 0 additions & 113 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 47 | 47 | import tokenize | 48 | 48 | import token | 49 | 49 | import types | 50 | | -import warnings | 51 | 50 | import functools | 52 | 51 | import builtins | 53 | 52 | from operator import attrgetter | @@ -1214,37 +1213,6 @@ def getargs(co): | 1214 | 1213 | varkw = co.co_varnames[nargs] | 1215 | 1214 | return Arguments(args + kwonlyargs, varargs, varkw) | 1216 | 1215 |
| 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) | 1248 | 1216 |
| 1249 | 1217 | FullArgSpec = namedtuple('FullArgSpec', | 1250 | 1218 | 'args, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, annotations') | @@ -1369,63 +1337,6 @@ def _formatannotation(annotation): | 1369 | 1337 | return formatannotation(annotation, module) | 1370 | 1338 | return _formatannotation | 1371 | 1339 |
| 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 | 1429 | 1340 |
| 1430 | 1341 | def formatargvalues(args, varargs, varkw, locals, | 1431 | 1342 | formatarg=str, | @@ -2932,30 +2843,6 @@ def __init__(self, parameters=None, *, return_annotation=_empty, | 2932 | 2843 | self._parameters = types.MappingProxyType(params) | 2933 | 2844 | self._return_annotation = return_annotation | 2934 | 2845 |
| 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 | | - | 2959 | 2846 | @classmethod | 2960 | 2847 | def from_callable(cls, obj, *, | 2961 | 2848 | follow_wrapped=True, globals=None, locals=None, eval_str=False): | |
|