mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-23 13:51:27 +08:00
Implement itemgetter partially
This commit is contained in:
@@ -83,7 +83,6 @@ def _iterate_argument_clinic(evaluator, arguments, parameters):
|
|||||||
elif stars == 2:
|
elif stars == 2:
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
key, argument = next(iterator, (None, None))
|
key, argument = next(iterator, (None, None))
|
||||||
print(stars)
|
|
||||||
if key is not None:
|
if key is not None:
|
||||||
debug.warning('Keyword arguments in argument clinic are currently not supported.')
|
debug.warning('Keyword arguments in argument clinic are currently not supported.')
|
||||||
raise ValueError
|
raise ValueError
|
||||||
|
|||||||
@@ -194,7 +194,7 @@ class ContextualizedName(ContextualizedNode):
|
|||||||
return indexes
|
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.compiled import CompiledObject
|
||||||
from jedi.evaluate.context.iterable import Slice
|
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)
|
return ContextSet.from_sets(execute_evaluated(c, *args, **kwargs) for c in self._set)
|
||||||
|
|
||||||
def get_item(self, *args, **kwargs):
|
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()
|
NO_CONTEXTS = ContextSet()
|
||||||
|
|||||||
@@ -388,21 +388,29 @@ def _random_choice(sequences):
|
|||||||
|
|
||||||
|
|
||||||
class ItemGetterCallable(object):
|
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.
|
# TODO this context is totally incomplete and will raise exceptions.
|
||||||
|
self.evaluator = evaluator
|
||||||
self._args_context_set = args_context_set
|
self._args_context_set = args_context_set
|
||||||
|
|
||||||
@repack_with_argument_clinic('item, /')
|
@repack_with_argument_clinic('item, /')
|
||||||
def py__call__(self, item):
|
def py__call__(self, item_context_set):
|
||||||
return self._args_context_set.py__getitem__(item)
|
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)
|
@argument_clinic('*args, /', want_obj=True, want_arguments=True)
|
||||||
def _operator_itemgetter(args_context_set, obj, arguments):
|
def _operator_itemgetter(args_context_set, obj, arguments):
|
||||||
final = obj.py__call__(arguments)
|
# final = obj.py__call__(arguments)
|
||||||
print(final)
|
# TODO use this as a context wrapper
|
||||||
return final
|
return ContextSet(ItemGetterCallable(obj.evaluator, args_context_set))
|
||||||
return ItemGetterCallable(args_context_set)
|
|
||||||
|
|
||||||
|
|
||||||
_implemented = {
|
_implemented = {
|
||||||
|
|||||||
@@ -247,12 +247,25 @@ with contextlib.closing('asd') as string:
|
|||||||
|
|
||||||
import operator
|
import operator
|
||||||
|
|
||||||
f = operator.itemgetter([1])
|
f = operator.itemgetter(1)
|
||||||
#? float()
|
#? float()
|
||||||
f([1.0])
|
f([1.0])
|
||||||
#? str()
|
#? str()
|
||||||
f([1, ''])
|
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
|
# shlex
|
||||||
# -----------------
|
# -----------------
|
||||||
|
|||||||
Reference in New Issue
Block a user