From fd78d672ebb362f0e5116ad7c0057da114b25b40 Mon Sep 17 00:00:00 2001 From: Marcel Hellkamp Date: Wed, 3 Aug 2022 12:48:42 +0200 Subject: 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. --- bottle.py | 37 +++++++++---------------------------- 1 file changed, 9 insertions(+), 28 deletions(-) diff --git a/bottle.py b/bottle.py index 1f78812..b789dd5 100755 --- a/bottle.py +++ b/bottle.py @@ -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]', '', 'exec')) -- cgit v1.2.1