Merge with master

This commit is contained in:
Dave Halter
2018-08-26 03:16:57 +02:00
2 changed files with 89 additions and 60 deletions

View File

@@ -9,14 +9,12 @@ Note that this module exists only to implement very specific functionality in
the standard library. The usual way to understand the standard library is the
compiled module that returns the types for C-builtins.
"""
import re
import parso
from jedi._compatibility import force_unicode
from jedi.plugins.base import BasePlugin
from jedi import debug
from jedi.evaluate.arguments import ValuesArguments
from jedi.evaluate.arguments import ValuesArguments, repack_with_argument_clinic
from jedi.evaluate import analysis
from jedi.evaluate import compiled
from jedi.evaluate.context.instance import \
@@ -85,8 +83,6 @@ class StdlibPlugin(BasePlugin):
if import_names == ('os', 'path'):
return parent_module_context.py__getattribute__('path')
return callback(evaluator, import_names, parent_module_context, sys_path)
return wrapper
@@ -103,42 +99,22 @@ def argument_clinic(string, want_obj=False, want_context=False, want_arguments=F
"""
Works like Argument Clinic (PEP 436), to validate function params.
"""
clinic_args = []
allow_kwargs = False
optional = False
while string:
# Optional arguments have to begin with a bracket. And should always be
# at the end of the arguments. This is therefore not a proper argument
# clinic implementation. `range()` for exmple allows an optional start
# value at the beginning.
match = re.match('(?:(?:(\[),? ?|, ?|)(\w+)|, ?/)\]*', string)
string = string[len(match.group(0)):]
if not match.group(2): # A slash -> allow named arguments
allow_kwargs = True
continue
optional = optional or bool(match.group(1))
word = match.group(2)
clinic_args.append((word, optional, allow_kwargs))
def f(func):
def wrapper(evaluator, obj, arguments):
@repack_with_argument_clinic(string, keep_arguments_param=True)
def wrapper(evaluator, obj, *args, **kwargs):
arguments = kwargs.pop('arguments')
assert not kwargs # Python 2...
debug.dbg('builtin start %s' % obj, color='MAGENTA')
result = NO_CONTEXTS
try:
lst = list(arguments.eval_argument_clinic(clinic_args))
except ValueError:
pass
else:
kwargs = {}
if want_context:
kwargs['context'] = arguments.context
if want_obj:
kwargs['obj'] = obj
if want_arguments:
kwargs['arguments'] = arguments
result = func(evaluator, *lst, **kwargs)
finally:
debug.dbg('builtin end: %s', result, color='MAGENTA')
if want_context:
kwargs['context'] = arguments.context
if want_obj:
kwargs['obj'] = obj
if want_arguments:
kwargs['arguments'] = arguments
result = func(evaluator, *args, **kwargs)
debug.dbg('builtin end: %s', result, color='MAGENTA')
return result
return wrapper
@@ -349,8 +325,8 @@ _implemented = {
'deepcopy': _return_first_param,
},
'json': {
'load': lambda *args: NO_CONTEXTS,
'loads': lambda *args: NO_CONTEXTS,
'load': lambda evaluator, obj, arguments: NO_CONTEXTS,
'loads': lambda evaluator, obj, arguments: NO_CONTEXTS,
},
'collections': {
'namedtuple': collections_namedtuple,