mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 22:14:27 +08:00
tests and improvements for __next__ and send generator methods
This commit is contained in:
@@ -303,6 +303,8 @@ class Evaluator(object):
|
||||
except stdlib.NotInStdLib:
|
||||
pass
|
||||
|
||||
if isinstance(obj, iterable.GeneratorMethod):
|
||||
return obj.execute()
|
||||
if obj.isinstance(compiled.CompiledObject):
|
||||
if obj.is_executable_class():
|
||||
return [er.Instance(self, obj, params)]
|
||||
@@ -311,8 +313,6 @@ class Evaluator(object):
|
||||
elif obj.isinstance(er.Class):
|
||||
# There maybe executions of executions.
|
||||
return [er.Instance(self, obj, params)]
|
||||
elif isinstance(obj, iterable.Generator):
|
||||
return obj.iter_content()
|
||||
else:
|
||||
stmts = []
|
||||
if obj.isinstance(er.Function):
|
||||
|
||||
@@ -28,10 +28,7 @@ class Generator(use_metaclass(CachedMetaClass, pr.Base)):
|
||||
executes_generator = '__next__', 'send', 'next'
|
||||
for name in compiled.generator_obj.get_defined_names():
|
||||
if name.name in executes_generator:
|
||||
print(name)
|
||||
parent = self
|
||||
# TODO parents are fucked up
|
||||
#pr.Function(module, name, [], (0, 0), None)
|
||||
parent = GeneratorMethod(self, name.parent)
|
||||
yield helpers.FakeName(name.name, parent)
|
||||
else:
|
||||
yield name
|
||||
@@ -56,6 +53,19 @@ class Generator(use_metaclass(CachedMetaClass, pr.Base)):
|
||||
return "<%s of %s>" % (type(self).__name__, self.func)
|
||||
|
||||
|
||||
class GeneratorMethod(object):
|
||||
"""``__next__`` and ``send`` methods."""
|
||||
def __init__(self, generator, builtin_func):
|
||||
self._builtin_func = builtin_func
|
||||
self._generator = generator
|
||||
|
||||
def execute(self):
|
||||
return self._generator.iter_content()
|
||||
|
||||
def __getattr__(self, name):
|
||||
return getattr(self._builtin_func, name)
|
||||
|
||||
|
||||
class Array(use_metaclass(CachedMetaClass, pr.Base)):
|
||||
"""
|
||||
Used as a mirror to pr.Array, if needed. It defines some getter
|
||||
|
||||
@@ -118,8 +118,21 @@ b
|
||||
#? ['__call__']
|
||||
gen().close.__call__
|
||||
|
||||
#?
|
||||
gen().throw()
|
||||
|
||||
#? ['co_consts']
|
||||
gen().gi_code.co_consts
|
||||
|
||||
#? []
|
||||
gen.gi_code.co_consts
|
||||
|
||||
# `send` is also a method wrapper.
|
||||
#? ['__call__']
|
||||
gen().send.__call__
|
||||
|
||||
#? tuple()
|
||||
gen().send()
|
||||
|
||||
#?
|
||||
gen()()
|
||||
|
||||
Reference in New Issue
Block a user