1
0
forked from VimPlug/jedi

Deprecate jedi.defined_names in favor of jedi.names.

This commit is contained in:
Dave Halter
2014-12-11 00:41:36 +01:00
parent 243fb8ef34
commit bb7bbf51ec
3 changed files with 16 additions and 11 deletions

View File

@@ -33,9 +33,8 @@ from jedi.evaluate import representation as er
from jedi.evaluate import compiled
from jedi.evaluate import imports
from jedi.evaluate.cache import memoize_default
from jedi.evaluate.helpers import FakeName, get_module_name_parts
from jedi.evaluate.helpers import FakeName, get_module_names
from jedi.evaluate.finder import get_names_of_scope, filter_private_variable
from jedi.evaluate.helpers import search_call_signatures
from jedi.evaluate import analysis
# Jedi uses lots and lots of recursion. By setting this a little bit higher, we
@@ -703,11 +702,13 @@ def defined_names(source, path=None, encoding='utf-8'):
(e.g., methods in class).
:rtype: list of classes.Definition
.. deprecated:: 0.9.0
Use :func:`names` instead.
.. todo:: Remove!
"""
grammar = load_grammar('grammar3.4')
parser = Parser(grammar, common.source_to_unicode(source, encoding),
module_path=path)
return classes.defined_names(Evaluator(grammar), parser.module)
warnings.warn("Use call_signatures instead.", DeprecationWarning)
return names(source, path, encoding)
def names(source=None, path=None, encoding='utf-8', all_scopes=False,
@@ -733,7 +734,7 @@ def names(source=None, path=None, encoding='utf-8', all_scopes=False,
# 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())]
for name_part in get_module_names(script._parser.module(), all_scopes)]
return sorted(filter(def_ref_filter, defs), key=lambda x: (x.line, x.column))

View File

@@ -283,12 +283,16 @@ def scan_statement_for_calls(stmt, search_name, assignment_details=False):
return result
def get_module_name_parts(module):
def get_module_names(module, all_scopes):
"""
Returns a dictionary with name parts as keys and their call paths as
values.
"""
return chain.from_iterable(module.used_names.values())
if all_scopes:
dct = module.used_names
else:
dct = module.names_dict
return chain.from_iterable(dct.values())
def statement_elements_in_statement(stmt):

View File

@@ -10,10 +10,10 @@ from ..helpers import TestCase
class TestDefinedNames(TestCase):
def assert_definition_names(self, definitions, names):
self.assertEqual([d.name for d in definitions], names)
assert [d.name for d in definitions] == names
def check_defined_names(self, source, names):
definitions = api.defined_names(textwrap.dedent(source))
definitions = api.names(textwrap.dedent(source))
self.assert_definition_names(definitions, names)
return definitions