fix some generator parents

This commit is contained in:
Dave Halter
2014-01-23 14:27:20 +01:00
parent c6b315aa2e
commit a1b68945ed
3 changed files with 17 additions and 9 deletions

View File

@@ -12,8 +12,6 @@ Changelog
* REPL completion is starting to become usable.
* Various small API changes. Generally this released focused on stability, though.
0.7.0 (2013-08-09)
++++++++++++++++++
* switched from LGPL to MIT license

View File

@@ -264,8 +264,14 @@ class Builtin(CompiledObject):
return [d for d in super(Builtin, self).get_defined_names() if d.name != 'None']
def _a_generator(foo):
"""Used to have an object to return for generators."""
yield 42
yield foo
builtin = Builtin(_builtins)
magic_function_class = CompiledObject(type(load_module), parent=builtin)
generator_obj = CompiledObject(_a_generator(1.0))
def _create_from_name(module, parent, name):

View File

@@ -8,6 +8,7 @@ from jedi.parser import representation as pr
from jedi.evaluate import compiled
from jedi.evaluate import helpers
from jedi.evaluate.cache import CachedMetaClass, memoize_default
from jedi.cache import underscore_memoization
class Generator(use_metaclass(CachedMetaClass, pr.Base)):
@@ -18,18 +19,21 @@ class Generator(use_metaclass(CachedMetaClass, pr.Base)):
self.func = func
self.var_args = var_args
@underscore_memoization
def get_defined_names(self):
"""
Returns a list of names that define a generator, which can return the
content of a generator.
"""
names = []
executes_generator = ('__next__', 'send')
for n in ('close', 'throw') + executes_generator:
parent = self if n in executes_generator else compiled.builtin
names.append(helpers.FakeName(n, parent))
debug.dbg('generator names: %s', names)
return names
executes_generator = '__next__', 'send', 'next'
for name in compiled.generator_obj.get_defined_names():
if name.name in executes_generator:
parent = self
# TODO parents are fucked up
#pr.Function(module, name, [], (0, 0), None)
yield helpers.FakeName(name, parent)
else:
yield name
def iter_content(self):
""" returns the content of __iter__ """