mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 22:44:27 +08:00
Remove code that is not needed anymore, because the Definition/Completion import is now standardized (to NamePart).
This commit is contained in:
@@ -10,7 +10,6 @@ from jedi._compatibility import next, unicode, use_metaclass
|
|||||||
from jedi import settings
|
from jedi import settings
|
||||||
from jedi import common
|
from jedi import common
|
||||||
from jedi.parser import representation as pr
|
from jedi.parser import representation as pr
|
||||||
from jedi.cache import underscore_memoization
|
|
||||||
from jedi.evaluate.helpers import statement_elements_in_statement
|
from jedi.evaluate.helpers import statement_elements_in_statement
|
||||||
from jedi.evaluate.cache import memoize_default, CachedMetaClass
|
from jedi.evaluate.cache import memoize_default, CachedMetaClass
|
||||||
from jedi.evaluate import representation as er
|
from jedi.evaluate import representation as er
|
||||||
@@ -152,12 +151,10 @@ class BaseDefinition(object):
|
|||||||
'function'
|
'function'
|
||||||
|
|
||||||
"""
|
"""
|
||||||
# generate the type
|
stripped = self._name.get_definition()
|
||||||
stripped = self._name
|
|
||||||
if isinstance(stripped, er.InstanceElement):
|
if isinstance(stripped, er.InstanceElement):
|
||||||
stripped = stripped.var
|
stripped = stripped.var
|
||||||
if isinstance(stripped, (pr.Name, pr.NamePart)):
|
|
||||||
stripped = stripped.get_definition()
|
|
||||||
if isinstance(stripped, compiled.CompiledObject):
|
if isinstance(stripped, compiled.CompiledObject):
|
||||||
return stripped.type()
|
return stripped.type()
|
||||||
if isinstance(stripped, iterable.Array):
|
if isinstance(stripped, iterable.Array):
|
||||||
@@ -257,9 +254,7 @@ class BaseDefinition(object):
|
|||||||
Document for function f.
|
Document for function f.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
definition = self._name
|
definition = self._name.get_definition()
|
||||||
if isinstance(definition, pr.NamePart):
|
|
||||||
definition = definition.parent.parent
|
|
||||||
if raw:
|
if raw:
|
||||||
return _Help(definition).raw()
|
return _Help(definition).raw()
|
||||||
else:
|
else:
|
||||||
@@ -337,9 +332,6 @@ class BaseDefinition(object):
|
|||||||
if element is name_part:
|
if element is name_part:
|
||||||
return call_path[:i + 1]
|
return call_path[:i + 1]
|
||||||
|
|
||||||
if not isinstance(self._name, pr.NamePart):
|
|
||||||
raise TypeError('Definition is not a NamePart.')
|
|
||||||
|
|
||||||
if self.type not in ('statement', 'import'):
|
if self.type not in ('statement', 'import'):
|
||||||
# Functions, classes and modules are already fixed definitions, we
|
# Functions, classes and modules are already fixed definitions, we
|
||||||
# cannot follow them anymore.
|
# cannot follow them anymore.
|
||||||
@@ -354,9 +346,7 @@ class BaseDefinition(object):
|
|||||||
"""
|
"""
|
||||||
Follow both statements and imports, as far as possible.
|
Follow both statements and imports, as far as possible.
|
||||||
"""
|
"""
|
||||||
stripped = self._name
|
stripped = self._name.get_definition()
|
||||||
if isinstance(stripped, (pr.Name, pr.NamePart)):
|
|
||||||
stripped = stripped.get_definition()
|
|
||||||
|
|
||||||
# We should probably work in `Finder._names_to_types` here.
|
# We should probably work in `Finder._names_to_types` here.
|
||||||
if isinstance(stripped, pr.Function):
|
if isinstance(stripped, pr.Function):
|
||||||
@@ -603,13 +593,9 @@ class Definition(use_metaclass(CachedMetaClass, BaseDefinition)):
|
|||||||
'class C'
|
'class C'
|
||||||
|
|
||||||
"""
|
"""
|
||||||
d = self._name
|
d = self._name.get_definition()
|
||||||
if isinstance(d, er.InstanceElement):
|
if isinstance(d, er.InstanceElement):
|
||||||
d = d.var
|
d = d.var
|
||||||
if isinstance(d, (pr.Name, pr.NamePart)):
|
|
||||||
d = d.get_definition()
|
|
||||||
if isinstance(d, er.InstanceElement):
|
|
||||||
d = d.var
|
|
||||||
|
|
||||||
if isinstance(d, compiled.CompiledObject):
|
if isinstance(d, compiled.CompiledObject):
|
||||||
typ = d.type()
|
typ = d.type()
|
||||||
@@ -664,14 +650,8 @@ class Definition(use_metaclass(CachedMetaClass, BaseDefinition)):
|
|||||||
Returns True, if defined as a name in a statement, function or class.
|
Returns True, if defined as a name in a statement, function or class.
|
||||||
Returns False, if it's a reference to such a definition.
|
Returns False, if it's a reference to such a definition.
|
||||||
"""
|
"""
|
||||||
if isinstance(self._name, compiled.CompiledName):
|
_def = self._name.get_parent_until((pr.ExprStmt, pr.Import,
|
||||||
return True
|
pr.Function, pr.Class, pr.Module))
|
||||||
if not isinstance(self._name, pr.NamePart):
|
|
||||||
# Currently only handle NameParts. Once we have a proper API, this
|
|
||||||
# will be the standard anyway.
|
|
||||||
raise NotImplementedError
|
|
||||||
_def = self._name.get_parent_until((pr.ExprStmt,
|
|
||||||
pr.Import, pr.Function, pr.Class, pr.Module))
|
|
||||||
if isinstance(_def, pr.ExprStmt):
|
if isinstance(_def, pr.ExprStmt):
|
||||||
exp_list = _def.expression_list()
|
exp_list = _def.expression_list()
|
||||||
return not exp_list or self._name.start_pos < exp_list[0].start_pos
|
return not exp_list or self._name.start_pos < exp_list[0].start_pos
|
||||||
|
|||||||
Reference in New Issue
Block a user