mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 14:34:31 +08:00
Introduce py__next__ to have more clear way to use __next__
This commit is contained in:
@@ -175,6 +175,9 @@ class Value(HelperValueMixin):
|
|||||||
message="TypeError: '%s' object is not iterable" % self)
|
message="TypeError: '%s' object is not iterable" % self)
|
||||||
return iter([])
|
return iter([])
|
||||||
|
|
||||||
|
def py__next__(self, contextualized_node=None):
|
||||||
|
return self.py__iter__(contextualized_node)
|
||||||
|
|
||||||
def get_signatures(self):
|
def get_signatures(self):
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|||||||
@@ -256,23 +256,23 @@ class _BaseTreeInstance(AbstractInstanceValue):
|
|||||||
|
|
||||||
def iterate():
|
def iterate():
|
||||||
for generator in self.execute_function_slots(iter_slot_names):
|
for generator in self.execute_function_slots(iter_slot_names):
|
||||||
if generator.is_instance() and not generator.is_compiled():
|
for lazy_value in generator.py__next__(contextualized_node):
|
||||||
|
yield lazy_value
|
||||||
|
return iterate()
|
||||||
|
|
||||||
|
def py__next__(self, contextualized_node=None):
|
||||||
# `__next__` logic.
|
# `__next__` logic.
|
||||||
if self.inference_state.environment.version_info.major == 2:
|
if self.inference_state.environment.version_info.major == 2:
|
||||||
name = u'next'
|
name = u'next'
|
||||||
else:
|
else:
|
||||||
name = u'__next__'
|
name = u'__next__'
|
||||||
next_slot_names = generator.get_function_slot_names(name)
|
next_slot_names = self.get_function_slot_names(name)
|
||||||
if next_slot_names:
|
if next_slot_names:
|
||||||
yield LazyKnownValues(
|
yield LazyKnownValues(
|
||||||
generator.execute_function_slots(next_slot_names)
|
self.execute_function_slots(next_slot_names)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
debug.warning('Instance has no __next__ function in %s.', generator)
|
debug.warning('Instance has no __next__ function in %s.', self)
|
||||||
else:
|
|
||||||
for lazy_value in generator.py__iter__():
|
|
||||||
yield lazy_value
|
|
||||||
return iterate()
|
|
||||||
|
|
||||||
def py__call__(self, arguments):
|
def py__call__(self, arguments):
|
||||||
names = self.get_function_slot_names(u'__call__')
|
names = self.get_function_slot_names(u'__call__')
|
||||||
|
|||||||
@@ -23,6 +23,9 @@ from jedi.inference.value.dynamic_arrays import check_array_additions
|
|||||||
|
|
||||||
|
|
||||||
class IterableMixin(object):
|
class IterableMixin(object):
|
||||||
|
def py__next__(self, contextualized_node=None):
|
||||||
|
return self.py__iter__(contextualized_node)
|
||||||
|
|
||||||
def py__stop_iteration_returns(self):
|
def py__stop_iteration_returns(self):
|
||||||
return ValueSet([compiled.builtin_from_name(self.inference_state, u'None')])
|
return ValueSet([compiled.builtin_from_name(self.inference_state, u'None')])
|
||||||
|
|
||||||
@@ -64,7 +67,7 @@ class GeneratorBase(LazyAttributeOverwrite, IterableMixin):
|
|||||||
@publish_method('send')
|
@publish_method('send')
|
||||||
@publish_method('next', python_version_match=2)
|
@publish_method('next', python_version_match=2)
|
||||||
@publish_method('__next__', python_version_match=3)
|
@publish_method('__next__', python_version_match=3)
|
||||||
def py__next__(self, arguments):
|
def _next(self, arguments):
|
||||||
return ValueSet.from_sets(lazy_value.infer() for lazy_value in self.py__iter__())
|
return ValueSet.from_sets(lazy_value.infer() for lazy_value in self.py__iter__())
|
||||||
|
|
||||||
def py__stop_iteration_returns(self):
|
def py__stop_iteration_returns(self):
|
||||||
|
|||||||
@@ -267,7 +267,7 @@ class ReversedObject(AttributeOverwrite):
|
|||||||
|
|
||||||
@publish_method('next', python_version_match=2)
|
@publish_method('next', python_version_match=2)
|
||||||
@publish_method('__next__', python_version_match=3)
|
@publish_method('__next__', python_version_match=3)
|
||||||
def py__next__(self, arguments):
|
def _next(self, arguments):
|
||||||
return ValueSet.from_sets(
|
return ValueSet.from_sets(
|
||||||
lazy_value.infer() for lazy_value in self._iter_list
|
lazy_value.infer() for lazy_value in self._iter_list
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user