Replaced django.utils.inspect.getargspec() with inspect.getfullargspec().
This commit is contained in:
parent
60dce33ab1
commit
620e9dd31a
|
@ -49,16 +49,15 @@ times with multiple contexts)
|
||||||
'<html></html>'
|
'<html></html>'
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import inspect
|
|
||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
|
from inspect import getcallargs, getfullargspec
|
||||||
|
|
||||||
from django.template.context import ( # NOQA: imported for backwards compatibility
|
from django.template.context import ( # NOQA: imported for backwards compatibility
|
||||||
BaseContext, Context, ContextPopException, RequestContext,
|
BaseContext, Context, ContextPopException, RequestContext,
|
||||||
)
|
)
|
||||||
from django.utils.formats import localize
|
from django.utils.formats import localize
|
||||||
from django.utils.html import conditional_escape, escape
|
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.safestring import SafeData, mark_safe
|
||||||
from django.utils.text import (
|
from django.utils.text import (
|
||||||
get_text_list, smart_split, unescape_string_literal,
|
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.
|
# Check to see if a decorator is providing the real function.
|
||||||
func = getattr(func, '_decorated_function', func)
|
func = getattr(func, '_decorated_function', func)
|
||||||
|
|
||||||
args, _, _, defaults = getargspec(func)
|
args, _, _, defaults, _, _, _ = getfullargspec(func)
|
||||||
alen = len(args)
|
alen = len(args)
|
||||||
dlen = len(defaults or [])
|
dlen = len(defaults or [])
|
||||||
# Not enough OR Too many
|
# Not enough OR Too many
|
||||||
|
@ -865,7 +864,7 @@ class Variable:
|
||||||
current = current()
|
current = current()
|
||||||
except TypeError:
|
except TypeError:
|
||||||
try:
|
try:
|
||||||
inspect.getcallargs(current)
|
getcallargs(current)
|
||||||
except TypeError: # arguments *were* required
|
except TypeError: # arguments *were* required
|
||||||
current = context.template.engine.string_if_invalid # invalid method call
|
current = context.template.engine.string_if_invalid # invalid method call
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import functools
|
import functools
|
||||||
from importlib import import_module
|
from importlib import import_module
|
||||||
|
from inspect import getfullargspec
|
||||||
|
|
||||||
from django.utils.html import conditional_escape
|
from django.utils.html import conditional_escape
|
||||||
from django.utils.inspect import getargspec
|
|
||||||
from django.utils.itercompat import is_iterable
|
from django.utils.itercompat import is_iterable
|
||||||
|
|
||||||
from .base import Node, Template, token_kwargs
|
from .base import Node, Template, token_kwargs
|
||||||
|
@ -106,7 +106,7 @@ class Library:
|
||||||
return 'world'
|
return 'world'
|
||||||
"""
|
"""
|
||||||
def dec(func):
|
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__)
|
function_name = (name or getattr(func, '_decorated_function', func).__name__)
|
||||||
|
|
||||||
@functools.wraps(func)
|
@functools.wraps(func)
|
||||||
|
@ -143,7 +143,7 @@ class Library:
|
||||||
return {'choices': choices}
|
return {'choices': choices}
|
||||||
"""
|
"""
|
||||||
def dec(func):
|
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__)
|
function_name = (name or getattr(func, '_decorated_function', func).__name__)
|
||||||
|
|
||||||
@functools.wraps(func)
|
@functools.wraps(func)
|
||||||
|
|
|
@ -1,29 +1,6 @@
|
||||||
import inspect
|
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):
|
def get_func_args(func):
|
||||||
sig = inspect.signature(func)
|
sig = inspect.signature(func)
|
||||||
return [
|
return [
|
||||||
|
|
Loading…
Reference in New Issue