diff --git a/jedi/evaluate_representation.py b/jedi/evaluate_representation.py index f5c6e991..3b5c972f 100644 --- a/jedi/evaluate_representation.py +++ b/jedi/evaluate_representation.py @@ -769,9 +769,13 @@ class Generator(use_metaclass(cache.CachedMetaClass, pr.Base)): debug.warning('Tried to get array access on a generator', self) return [] - @property - def parent(self): - return self.func.parent + def __getattr__(self, name): + if name not in ['start_pos', 'end_pos', 'parent', 'get_imports', + 'asserts', 'doc', 'docstr', 'get_parent_until', 'get_code', + 'subscopes']: + raise AttributeError("Accessing %s of %s is not allowed." + % (self, name)) + return getattr(self.func, name) def __repr__(self): return "<%s of %s>" % (type(self).__name__, self.func) diff --git a/test/test_api_classes.py b/test/test_api_classes.py index bcb7a722..2da3e13e 100644 --- a/test/test_api_classes.py +++ b/test/test_api_classes.py @@ -32,7 +32,7 @@ def make_definitions(): definitions += api.defined_names(source) source += textwrap.dedent(""" - variable = sys or C or x or f or g or h""") + variable = sys or C or x or f or g or g() or h""") lines = source.splitlines() script = api.Script(source, len(lines), len('variable'), None) definitions += script.definition() @@ -50,4 +50,4 @@ def make_definitions(): @pytest.mark.parametrize('definition', make_definitions()) def test_basedefinition_type(definition): assert definition.type in ('module', 'class', 'instance', 'function', - 'statement', 'import', 'param') + 'generator', 'statement', 'import', 'param')