forked from VimPlug/jedi
Implement itemgetter partially
This commit is contained in:
@@ -83,7 +83,6 @@ def _iterate_argument_clinic(evaluator, arguments, parameters):
|
||||
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
|
||||
|
||||
@@ -194,7 +194,7 @@ class ContextualizedName(ContextualizedNode):
|
||||
return indexes
|
||||
|
||||
|
||||
def _get_item(context, index_contexts, contextualized_node):
|
||||
def _getitem(context, index_contexts, contextualized_node):
|
||||
from jedi.evaluate.compiled import CompiledObject
|
||||
from jedi.evaluate.context.iterable import Slice
|
||||
|
||||
@@ -254,7 +254,7 @@ class ContextSet(BaseContextSet):
|
||||
return ContextSet.from_sets(execute_evaluated(c, *args, **kwargs) for c in self._set)
|
||||
|
||||
def get_item(self, *args, **kwargs):
|
||||
return ContextSet.from_sets(_get_item(c, *args, **kwargs) for c in self._set)
|
||||
return ContextSet.from_sets(_getitem(c, *args, **kwargs) for c in self._set)
|
||||
|
||||
|
||||
NO_CONTEXTS = ContextSet()
|
||||
|
||||
@@ -388,21 +388,29 @@ def _random_choice(sequences):
|
||||
|
||||
|
||||
class ItemGetterCallable(object):
|
||||
def __init__(self, args_context_set):
|
||||
def __init__(self, evaluator, args_context_set):
|
||||
# TODO this context is totally incomplete and will raise exceptions.
|
||||
self.evaluator = evaluator
|
||||
self._args_context_set = args_context_set
|
||||
|
||||
@repack_with_argument_clinic('item, /')
|
||||
def py__call__(self, item):
|
||||
return self._args_context_set.py__getitem__(item)
|
||||
def py__call__(self, item_context_set):
|
||||
context_set = ContextSet()
|
||||
for args_context in self._args_context_set:
|
||||
lazy_contexts = list(args_context.py__iter__())
|
||||
if len(lazy_contexts) == 1:
|
||||
# TODO we need to add the contextualized context.
|
||||
context_set |= item_context_set.get_item(lazy_contexts[0].infer(), None)
|
||||
else:
|
||||
raise NotImplementedError
|
||||
return context_set
|
||||
|
||||
|
||||
@argument_clinic('*args, /', want_obj=True, want_arguments=True)
|
||||
def _operator_itemgetter(args_context_set, obj, arguments):
|
||||
final = obj.py__call__(arguments)
|
||||
print(final)
|
||||
return final
|
||||
return ItemGetterCallable(args_context_set)
|
||||
# final = obj.py__call__(arguments)
|
||||
# TODO use this as a context wrapper
|
||||
return ContextSet(ItemGetterCallable(obj.evaluator, args_context_set))
|
||||
|
||||
|
||||
_implemented = {
|
||||
|
||||
@@ -247,12 +247,25 @@ with contextlib.closing('asd') as string:
|
||||
|
||||
import operator
|
||||
|
||||
f = operator.itemgetter([1])
|
||||
f = operator.itemgetter(1)
|
||||
#? float()
|
||||
f([1.0])
|
||||
#? str()
|
||||
f([1, ''])
|
||||
|
||||
g = operator.itemgetter(1, 2)
|
||||
x1, x2 = g([1, 1.0, ''])
|
||||
#? float()
|
||||
x1
|
||||
#? float()
|
||||
x2
|
||||
|
||||
x1, x2 = g([1, ''])
|
||||
#? str()
|
||||
x1
|
||||
#? int() str()
|
||||
x2
|
||||
|
||||
# -----------------
|
||||
# shlex
|
||||
# -----------------
|
||||
|
||||
Reference in New Issue
Block a user