mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
bpo-33582: Emit deprecation warning for formatargspec
(GH-6994)
This commit is contained in:
parent
fd88f319a4
commit
46c5cd0f6e
3 changed files with 21 additions and 6 deletions
|
@ -18,7 +18,7 @@ Here are some of the useful functions provided by this module:
|
||||||
|
|
||||||
getargvalues(), getcallargs() - get info about function arguments
|
getargvalues(), getcallargs() - get info about function arguments
|
||||||
getfullargspec() - same, with support for Python 3 features
|
getfullargspec() - same, with support for Python 3 features
|
||||||
formatargspec(), formatargvalues() - format an argument spec
|
formatargvalues() - format an argument spec
|
||||||
getouterframes(), getinnerframes() - get info about frames
|
getouterframes(), getinnerframes() - get info about frames
|
||||||
currentframe() - get the current stack frame
|
currentframe() - get the current stack frame
|
||||||
stack(), trace() - get info about frames on the stack or in a traceback
|
stack(), trace() - get info about frames on the stack or in a traceback
|
||||||
|
@ -1211,7 +1211,19 @@ def formatargspec(args, varargs=None, varkw=None, defaults=None,
|
||||||
kwonlyargs, kwonlydefaults, annotations). The other five arguments
|
kwonlyargs, kwonlydefaults, annotations). The other five arguments
|
||||||
are the corresponding optional formatting functions that are called to
|
are the corresponding optional formatting functions that are called to
|
||||||
turn names and values into strings. The last argument is an optional
|
turn names and values into strings. The last argument is an optional
|
||||||
function to format the sequence of arguments."""
|
function to format the sequence of arguments.
|
||||||
|
|
||||||
|
Deprecated since Python 3.5: use the `signature` function and `Signature`
|
||||||
|
objects.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from warnings import warn
|
||||||
|
|
||||||
|
warn("`formatargspec` is deprecated since Python 3.5. Use `signature` and "
|
||||||
|
" the `Signature` object directly",
|
||||||
|
DeprecationWarning,
|
||||||
|
stacklevel=2)
|
||||||
|
|
||||||
def formatargandannotation(arg):
|
def formatargandannotation(arg):
|
||||||
result = formatarg(arg)
|
result = formatarg(arg)
|
||||||
if arg in annotations:
|
if arg in annotations:
|
||||||
|
|
|
@ -712,6 +712,7 @@ class TestClassesAndFunctions(unittest.TestCase):
|
||||||
self.assertEqual(varkw, varkw_e)
|
self.assertEqual(varkw, varkw_e)
|
||||||
self.assertEqual(defaults, defaults_e)
|
self.assertEqual(defaults, defaults_e)
|
||||||
if formatted is not None:
|
if formatted is not None:
|
||||||
|
with self.assertWarns(DeprecationWarning):
|
||||||
self.assertEqual(inspect.formatargspec(args, varargs, varkw, defaults),
|
self.assertEqual(inspect.formatargspec(args, varargs, varkw, defaults),
|
||||||
formatted)
|
formatted)
|
||||||
|
|
||||||
|
@ -729,6 +730,7 @@ class TestClassesAndFunctions(unittest.TestCase):
|
||||||
self.assertEqual(kwonlydefaults, kwonlydefaults_e)
|
self.assertEqual(kwonlydefaults, kwonlydefaults_e)
|
||||||
self.assertEqual(ann, ann_e)
|
self.assertEqual(ann, ann_e)
|
||||||
if formatted is not None:
|
if formatted is not None:
|
||||||
|
with self.assertWarns(DeprecationWarning):
|
||||||
self.assertEqual(inspect.formatargspec(args, varargs, varkw, defaults,
|
self.assertEqual(inspect.formatargspec(args, varargs, varkw, defaults,
|
||||||
kwonlyargs, kwonlydefaults, ann),
|
kwonlyargs, kwonlydefaults, ann),
|
||||||
formatted)
|
formatted)
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Emit a deprecation warning for inspect.formatargspec
|
Loading…
Add table
Add a link
Reference in a new issue