mirror of
https://github.com/davidhalter/jedi.git
synced 2026-05-24 17:28:36 +08:00
Merge pull request #177 from tkf/Generator-object-has-no-attribute-start_pos
Generator object has no attribute start_pos (added a failing test)
This commit is contained in:
@@ -769,9 +769,13 @@ class Generator(use_metaclass(cache.CachedMetaClass, pr.Base)):
|
|||||||
debug.warning('Tried to get array access on a generator', self)
|
debug.warning('Tried to get array access on a generator', self)
|
||||||
return []
|
return []
|
||||||
|
|
||||||
@property
|
def __getattr__(self, name):
|
||||||
def parent(self):
|
if name not in ['start_pos', 'end_pos', 'parent', 'get_imports',
|
||||||
return self.func.parent
|
'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):
|
def __repr__(self):
|
||||||
return "<%s of %s>" % (type(self).__name__, self.func)
|
return "<%s of %s>" % (type(self).__name__, self.func)
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ def make_definitions():
|
|||||||
definitions += api.defined_names(source)
|
definitions += api.defined_names(source)
|
||||||
|
|
||||||
source += textwrap.dedent("""
|
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()
|
lines = source.splitlines()
|
||||||
script = api.Script(source, len(lines), len('variable'), None)
|
script = api.Script(source, len(lines), len('variable'), None)
|
||||||
definitions += script.definition()
|
definitions += script.definition()
|
||||||
@@ -50,4 +50,4 @@ def make_definitions():
|
|||||||
@pytest.mark.parametrize('definition', make_definitions())
|
@pytest.mark.parametrize('definition', make_definitions())
|
||||||
def test_basedefinition_type(definition):
|
def test_basedefinition_type(definition):
|
||||||
assert definition.type in ('module', 'class', 'instance', 'function',
|
assert definition.type in ('module', 'class', 'instance', 'function',
|
||||||
'statement', 'import', 'param')
|
'generator', 'statement', 'import', 'param')
|
||||||
|
|||||||
Reference in New Issue
Block a user