|
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):
|
|
0 commit comments