From 620e9dd31a2146d70de740f96a8cb9a6db054fc7 Mon Sep 17 00:00:00 2001 From: Alexander Allakhverdiyev Date: Thu, 27 Apr 2017 17:42:49 -0700 Subject: [PATCH] Replaced django.utils.inspect.getargspec() with inspect.getfullargspec(). --- django/template/base.py | 7 +++---- django/template/library.py | 6 +++--- django/utils/inspect.py | 23 ----------------------- 3 files changed, 6 insertions(+), 30 deletions(-) diff --git a/django/template/base.py b/django/template/base.py index 930b6922f7..9ceba80dae 100644 --- a/django/template/base.py +++ b/django/template/base.py @@ -49,16 +49,15 @@ times with multiple contexts) '' """ -import inspect import logging import re +from inspect import getcallargs, getfullargspec from django.template.context import ( # NOQA: imported for backwards compatibility BaseContext, Context, ContextPopException, RequestContext, ) from django.utils.formats import localize from django.utils.html import conditional_escape, escape -from django.utils.inspect import getargspec from django.utils.safestring import SafeData, mark_safe from django.utils.text import ( get_text_list, smart_split, unescape_string_literal, @@ -715,7 +714,7 @@ class FilterExpression: # Check to see if a decorator is providing the real function. func = getattr(func, '_decorated_function', func) - args, _, _, defaults = getargspec(func) + args, _, _, defaults, _, _, _ = getfullargspec(func) alen = len(args) dlen = len(defaults or []) # Not enough OR Too many @@ -865,7 +864,7 @@ class Variable: current = current() except TypeError: try: - inspect.getcallargs(current) + getcallargs(current) except TypeError: # arguments *were* required current = context.template.engine.string_if_invalid # invalid method call else: diff --git a/django/template/library.py b/django/template/library.py index 005255f484..c319a04340 100644 --- a/django/template/library.py +++ b/django/template/library.py @@ -1,8 +1,8 @@ import functools from importlib import import_module +from inspect import getfullargspec from django.utils.html import conditional_escape -from django.utils.inspect import getargspec from django.utils.itercompat import is_iterable from .base import Node, Template, token_kwargs @@ -106,7 +106,7 @@ class Library: return 'world' """ def dec(func): - params, varargs, varkw, defaults = getargspec(func) + params, varargs, varkw, defaults, _, _, _ = getfullargspec(func) function_name = (name or getattr(func, '_decorated_function', func).__name__) @functools.wraps(func) @@ -143,7 +143,7 @@ class Library: return {'choices': choices} """ def dec(func): - params, varargs, varkw, defaults = getargspec(func) + params, varargs, varkw, defaults, _, _, _ = getfullargspec(func) function_name = (name or getattr(func, '_decorated_function', func).__name__) @functools.wraps(func) diff --git a/django/utils/inspect.py b/django/utils/inspect.py index 9ef28bbf00..355cac48f3 100644 --- a/django/utils/inspect.py +++ b/django/utils/inspect.py @@ -1,29 +1,6 @@ import inspect -def getargspec(func): - sig = inspect.signature(func) - args = [ - p.name for p in sig.parameters.values() - if p.kind == inspect.Parameter.POSITIONAL_OR_KEYWORD - ] - varargs = [ - p.name for p in sig.parameters.values() - if p.kind == inspect.Parameter.VAR_POSITIONAL - ] - varargs = varargs[0] if varargs else None - varkw = [ - p.name for p in sig.parameters.values() - if p.kind == inspect.Parameter.VAR_KEYWORD - ] - varkw = varkw[0] if varkw else None - defaults = [ - p.default for p in sig.parameters.values() - if p.kind == inspect.Parameter.POSITIONAL_OR_KEYWORD and p.default is not p.empty - ] or None - return args, varargs, varkw, defaults - - def get_func_args(func): sig = inspect.signature(func) return [