forked from VimPlug/jedi
Add a temporary api._names, to make it possible to annotate a full script with types.
This commit is contained in:
@@ -32,7 +32,7 @@ from jedi.evaluate import Evaluator, filter_private_variable
|
||||
from jedi.evaluate import representation as er
|
||||
from jedi.evaluate import compiled
|
||||
from jedi.evaluate import imports
|
||||
from jedi.evaluate.helpers import FakeName
|
||||
from jedi.evaluate.helpers import FakeName, get_module_name_parts
|
||||
from jedi.evaluate.finder import get_names_of_scope
|
||||
from jedi.evaluate.helpers import search_call_signatures
|
||||
from jedi.evaluate import analysis
|
||||
@@ -688,6 +688,14 @@ def defined_names(source, path=None, encoding='utf-8'):
|
||||
return classes.defined_names(Evaluator(), parser.module)
|
||||
|
||||
|
||||
def _names(source=None, path=None, encoding='utf-8'):
|
||||
# Set line/column to a random position, because they don't matter.
|
||||
script = Script(source, line=1, column=0, path=path, encoding=encoding)
|
||||
defs = [classes.Definition(script._evaluator, name_part)
|
||||
for name_part in get_module_name_parts(script._parser.module())]
|
||||
return sorted(defs, key=lambda x: (x.line, x.column))
|
||||
|
||||
|
||||
def preload_module(*modules):
|
||||
"""
|
||||
Preloading modules tells Jedi to load a module now, instead of lazy parsing
|
||||
|
||||
@@ -309,6 +309,19 @@ class BaseDefinition(object):
|
||||
|
||||
return '.'.join(path if path[0] else path[1:])
|
||||
|
||||
def goto_assignments(self):
|
||||
if not isinstance(self._definition, pr.NamePart):
|
||||
raise TypeError('Definition is not a NamePart.')
|
||||
|
||||
if self.type not in ('statement', 'import'):
|
||||
# Functions, classes and modules are already fixed definitions, we
|
||||
# cannot follow them anymore.
|
||||
return [self]
|
||||
stmt_or_imp = self._definition.parent.parent
|
||||
|
||||
names, _ = self._evaluator.goto(stmt_or_imp, [self._definition])
|
||||
return [Definition(self._evaluator, n) for n in names]
|
||||
|
||||
@memoize_default()
|
||||
def _follow_statements_imports(self):
|
||||
"""
|
||||
|
||||
@@ -191,6 +191,10 @@ def scan_statement_for_calls(stmt, search_name, assignment_details=False):
|
||||
|
||||
|
||||
def get_module_name_parts(module):
|
||||
"""
|
||||
Returns a dictionary with name parts as keys and their call paths as
|
||||
values.
|
||||
"""
|
||||
def scope_name_parts(scope):
|
||||
for s in scope.subscopes:
|
||||
# Yield the name parts, not names.
|
||||
|
||||
Reference in New Issue
Block a user