forked from VimPlug/jedi
Rename Name.get_parent_stmt to Name.get_definition, because it's not always a statement. Also start using it in the NameFinder.
This commit is contained in:
@@ -85,7 +85,7 @@ class NameFinder(object):
|
|||||||
if unicode(self.name_str) != name.get_code():
|
if unicode(self.name_str) != name.get_code():
|
||||||
continue
|
continue
|
||||||
|
|
||||||
stmt = name.parent
|
stmt = name.get_definition()
|
||||||
scope = stmt.parent
|
scope = stmt.parent
|
||||||
if scope in break_scopes:
|
if scope in break_scopes:
|
||||||
continue
|
continue
|
||||||
@@ -219,7 +219,7 @@ class NameFinder(object):
|
|||||||
flow_scope = flow_scope.parent
|
flow_scope = flow_scope.parent
|
||||||
|
|
||||||
for name in names:
|
for name in names:
|
||||||
typ = name.parent
|
typ = name.get_definition()
|
||||||
if typ.isinstance(pr.ForFlow):
|
if typ.isinstance(pr.ForFlow):
|
||||||
types += self._handle_for_loops(typ)
|
types += self._handle_for_loops(typ)
|
||||||
elif isinstance(typ, pr.Param):
|
elif isinstance(typ, pr.Param):
|
||||||
|
|||||||
@@ -309,6 +309,9 @@ class FakeName(pr.Name):
|
|||||||
names = [(name_or_names, p)]
|
names = [(name_or_names, p)]
|
||||||
super(FakeName, self).__init__(FakeSubModule, names, p, p, parent)
|
super(FakeName, self).__init__(FakeSubModule, names, p, p, parent)
|
||||||
|
|
||||||
|
def get_definition(self):
|
||||||
|
return self.parent
|
||||||
|
|
||||||
|
|
||||||
class LazyName(FakeName):
|
class LazyName(FakeName):
|
||||||
def __init__(self, name, parent_callback):
|
def __init__(self, name, parent_callback):
|
||||||
|
|||||||
@@ -232,8 +232,9 @@ class ArrayMethod(IterableWrapper):
|
|||||||
|
|
||||||
def __getattr__(self, name):
|
def __getattr__(self, name):
|
||||||
# Set access privileges:
|
# Set access privileges:
|
||||||
if name not in ['parent', 'names', 'start_pos', 'end_pos', 'get_code']:
|
if name not in ['parent', 'names', 'start_pos', 'end_pos', 'get_code',
|
||||||
raise AttributeError('Strange accesson %s: %s.' % (self, name))
|
'get_definition']:
|
||||||
|
raise AttributeError('Strange access on %s: %s.' % (self, name))
|
||||||
return getattr(self.name, name)
|
return getattr(self.name, name)
|
||||||
|
|
||||||
def get_parent_until(self):
|
def get_parent_until(self):
|
||||||
|
|||||||
@@ -270,6 +270,9 @@ class InstanceElement(use_metaclass(CachedMetaClass, pr.Base)):
|
|||||||
def get_parent_until(self, *args, **kwargs):
|
def get_parent_until(self, *args, **kwargs):
|
||||||
return pr.Simple.get_parent_until(self, *args, **kwargs)
|
return pr.Simple.get_parent_until(self, *args, **kwargs)
|
||||||
|
|
||||||
|
def get_definition(self):
|
||||||
|
return self.get_parent_until((pr.Statement, pr.IsScope, pr.Import))
|
||||||
|
|
||||||
def get_decorated_func(self):
|
def get_decorated_func(self):
|
||||||
""" Needed because the InstanceElement should not be stripped """
|
""" Needed because the InstanceElement should not be stripped """
|
||||||
func = self.var.get_decorated_func()
|
func = self.var.get_decorated_func()
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ import re
|
|||||||
from inspect import cleandoc
|
from inspect import cleandoc
|
||||||
|
|
||||||
from jedi._compatibility import (next, Python3Method, encoding, unicode,
|
from jedi._compatibility import (next, Python3Method, encoding, unicode,
|
||||||
is_py3, u, literal_eval)
|
is_py3, u, literal_eval, use_metaclass)
|
||||||
from jedi import common
|
from jedi import common
|
||||||
from jedi import debug
|
from jedi import debug
|
||||||
from jedi import cache
|
from jedi import cache
|
||||||
@@ -222,6 +222,15 @@ class Simple(Base):
|
|||||||
(type(self).__name__, code, self.start_pos[0], self.start_pos[1])
|
(type(self).__name__, code, self.start_pos[0], self.start_pos[1])
|
||||||
|
|
||||||
|
|
||||||
|
class IsScopeMeta(type):
|
||||||
|
def __instancecheck__(self, other):
|
||||||
|
return other.is_scope()
|
||||||
|
|
||||||
|
|
||||||
|
class IsScope(use_metaclass(IsScopeMeta)):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class Scope(Simple, DocstringMixin):
|
class Scope(Simple, DocstringMixin):
|
||||||
"""
|
"""
|
||||||
Super class for the parser tree, which represents the state of a python
|
Super class for the parser tree, which represents the state of a python
|
||||||
@@ -1463,8 +1472,8 @@ class NamePart(object):
|
|||||||
def get_code(self):
|
def get_code(self):
|
||||||
return self._string
|
return self._string
|
||||||
|
|
||||||
def get_parent_stmt(self):
|
def get_definition(self):
|
||||||
return self.parent.parent_stmt()
|
return self.parent.get_definition()
|
||||||
|
|
||||||
def get_parent_until(self, *args, **kwargs):
|
def get_parent_until(self, *args, **kwargs):
|
||||||
return self.parent.get_parent_until(*args, **kwargs)
|
return self.parent.get_parent_until(*args, **kwargs)
|
||||||
@@ -1504,8 +1513,9 @@ class Name(Simple):
|
|||||||
""" Returns the names in a full string format """
|
""" Returns the names in a full string format """
|
||||||
return self._get_code
|
return self._get_code
|
||||||
|
|
||||||
def get_parent_stmt(self):
|
def get_definition(self):
|
||||||
return self.get_parent_until(ExprStmt)
|
# TODO This is way to complicated, simplify this with a new parser.
|
||||||
|
return self.get_parent_until((Statement, IsScope, Import))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def end_pos(self):
|
def end_pos(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user