diff options
author | Marcel Hellkamp <marcel.hellkamp@gwdg.de> | 2022-08-03 12:48:42 +0200 |
---|---|---|
committer | Marcel Hellkamp <marcel.hellkamp@gwdg.de> | 2022-08-03 12:48:42 +0200 |
commit | fd78d672ebb362f0e5116ad7c0057da114b25b40 (patch) | |
tree | fa79d4f3ed84f202fdfcad2c572b72d379a1ad15 | |
parent | d21be50c20fbd926a06becd51dbb382a537c1647 (diff) | |
download | bottle-fd78d672ebb362f0e5116ad7c0057da114b25b40.tar.gz |
cleanup: Simplified inspect.getargspec polyfills.
getfullargspec was deprecated in 3.5 and un-deprecated in 3.6,
so we can use that and do not need the inspect.signature() based
polyfill.
-rwxr-xr-x | bottle.py | 37 |
1 files changed, 9 insertions, 28 deletions
@@ -83,34 +83,6 @@ try: except ImportError: from json import dumps as json_dumps, loads as json_lds -# inspect.getargspec was removed in Python 3.6, use -# Signature-based version where we can (Python 3.3+) -try: - from inspect import signature - def getargspec(func): - params = signature(func).parameters - args, varargs, keywords, defaults = [], None, None, [] - for name, param in params.items(): - if param.kind == param.VAR_POSITIONAL: - varargs = name - elif param.kind == param.VAR_KEYWORD: - keywords = name - else: - args.append(name) - if param.default is not param.empty: - defaults.append(param.default) - return (args, varargs, keywords, tuple(defaults) or None) -except ImportError: - try: - from inspect import getfullargspec - def getargspec(func): - spec = getfullargspec(func) - kwargs = makelist(spec[0]) + makelist(spec.kwonlyargs) - return kwargs, spec[1], spec[2], spec[3] - except ImportError: - from inspect import getargspec - - py = sys.version_info py3k = py.major > 2 @@ -127,6 +99,13 @@ if py3k: import pickle from io import BytesIO import configparser + # getfullargspec was deprecated in 3.5 and un-deprecated in 3.6 + # getargspec was deprecated in 3.0 and removed in 3.11 + from inspect import getfullargspec + def getargspec(func): + spec = getfullargspec(func) + kwargs = makelist(spec[0]) + makelist(spec.kwonlyargs) + return kwargs, spec[1], spec[2], spec[3] basestring = str unicode = str @@ -148,6 +127,8 @@ else: # 2.x from StringIO import StringIO as BytesIO import ConfigParser as configparser from collections import MutableMapping as DictMixin + from inspect import getargspec + unicode = unicode json_loads = json_lds exec(compile('def _raise(*a): raise a[0], a[1], a[2]', '<py3fix>', 'exec')) |