1
0
forked from VimPlug/jedi

WIP of namedtuple/itemgetter/property

This commit is contained in:
Dave Halter
2018-09-03 09:50:45 +02:00
parent 0edc63ca8b
commit 39f1dfc85e
5 changed files with 106 additions and 18 deletions

View File

@@ -4,12 +4,12 @@ from parso.python import tree
from jedi._compatibility import zip_longest
from jedi import debug
from jedi.evaluate.utils import to_list
from jedi.evaluate.utils import to_list, PushBackIterator
from jedi.evaluate import analysis
from jedi.evaluate.lazy_context import LazyKnownContext, LazyKnownContexts, \
LazyTreeContext, get_merged_lazy_context
from jedi.evaluate.filters import ParamName
from jedi.evaluate.base_context import NO_CONTEXTS
from jedi.evaluate.base_context import NO_CONTEXTS, ContextSet
from jedi.evaluate.context import iterable
from jedi.evaluate.param import get_executed_params, ExecutedParam
@@ -63,9 +63,23 @@ def repack_with_argument_clinic(string, keep_arguments_param=False):
def _iterate_argument_clinic(arguments, parameters):
"""Uses a list with argument clinic information (see PEP 436)."""
iterator = arguments.unpack()
for i, (name, optional, allow_kwargs) in enumerate(parameters):
iterator = PushBackIterator(arguments.unpack())
for i, (name, optional, allow_kwargs, stars) in enumerate(parameters):
if stars == 1:
lazy_contexts = []
for key, argument in iterator:
if key is not None:
iterator.push_back((key, argument))
break
lazy_contexts.append(argument)
yield ContextSet(iterable.FakeSequence(evaluator, u'tuple', lazy_contexts))
lazy_contexts
continue
elif stars == 2:
raise NotImplementedError()
key, argument = next(iterator, (None, None))
print(stars)
if key is not None:
debug.warning('Keyword arguments in argument clinic are currently not supported.')
raise ValueError
@@ -93,14 +107,18 @@ def _parse_argument_clinic(string):
# 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)
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)
yield (word, optional, allow_kwargs)
stars = word.count('*')
word = word[stars:]
yield (word, optional, allow_kwargs, stars)
if stars:
allow_kwargs = True
class AbstractArguments(object):

View File

@@ -122,6 +122,17 @@ def iterate_contexts(contexts, contextualized_node=None, is_async=False):
)
class ContextWrapper(object):
def __init__(self, wrapped_context):
self._wrapped_context = wrapped_context
def __getattr__(self, name):
return getattr(self._wrapped_context, name)
def __repr__(self):
return '%s(%s)' % (self.__class__.__name__, self._wrapped_context)
class TreeContext(Context):
def __init__(self, evaluator, parent_context, tree_node):
super(TreeContext, self).__init__(evaluator, parent_context)

View File

@@ -318,8 +318,8 @@ class BoundMethod(AbstractFunction):
function.parent_context,
function.tree_node,
)
self._instance = instance
self._class = klass
self.instance = instance
self.class_context = klass
self._function = function
def py__class__(self):
@@ -327,9 +327,9 @@ class BoundMethod(AbstractFunction):
def _get_arguments(self, arguments):
if arguments is None:
arguments = AnonymousInstanceArguments(self._instance)
arguments = AnonymousInstanceArguments(self.instance)
return InstanceArguments(self._instance, arguments)
return InstanceArguments(self.instance, arguments)
def get_function_execution(self, arguments=None):
arguments = self._get_arguments(arguments)
@@ -344,7 +344,7 @@ class BoundMethod(AbstractFunction):
return self._function.get_function_execution(arguments)
def get_default_param_context(self):
return self._class
return self.class_context
def py__call__(self, arguments):
if isinstance(self._function, OverloadedFunctionContext):