mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-10 07:41:51 +08:00
Rename api.get_definitions to defined_names
Do the same for Definition.get_definitions also.
This commit is contained in:
@@ -468,14 +468,14 @@ class Script(object):
|
|||||||
api_classes._clear_caches()
|
api_classes._clear_caches()
|
||||||
|
|
||||||
|
|
||||||
def get_definitions(source, source_path=None, source_encoding='utf-8'):
|
def defined_names(source, source_path=None, source_encoding='utf-8'):
|
||||||
"""
|
"""
|
||||||
Get all definitions in `source` sorted by its position.
|
Get all definitions in `source` sorted by its position.
|
||||||
|
|
||||||
This functions can be used for listing functions, classes and
|
This functions can be used for listing functions, classes and
|
||||||
data defined in a file. This can be useful if you want to list
|
data defined in a file. This can be useful if you want to list
|
||||||
them in "sidebar". Each element in the returned list also has
|
them in "sidebar". Each element in the returned list also has
|
||||||
`get_definition` method which can be used to get sub-definitions
|
`defined_names` method which can be used to get sub-definitions
|
||||||
(e.g., methods in class).
|
(e.g., methods in class).
|
||||||
|
|
||||||
:rtype: list of api_classes.Definition
|
:rtype: list of api_classes.Definition
|
||||||
@@ -484,7 +484,7 @@ def get_definitions(source, source_path=None, source_encoding='utf-8'):
|
|||||||
modules.source_to_unicode(source, source_encoding),
|
modules.source_to_unicode(source, source_encoding),
|
||||||
module_path=source_path,
|
module_path=source_path,
|
||||||
)
|
)
|
||||||
return api_classes.get_definitions(parser.scope)
|
return api_classes.defined_names(parser.scope)
|
||||||
|
|
||||||
|
|
||||||
def set_debug_function(func_cb=debug.print_to_stdout, warnings=True,
|
def set_debug_function(func_cb=debug.print_to_stdout, warnings=True,
|
||||||
|
|||||||
@@ -354,7 +354,7 @@ class Definition(BaseDefinition):
|
|||||||
position = ''
|
position = ''
|
||||||
return "%s:%s%s" % (self.module_name, self.description, position)
|
return "%s:%s%s" % (self.module_name, self.description, position)
|
||||||
|
|
||||||
def get_definitions(self):
|
def defined_names(self):
|
||||||
"""
|
"""
|
||||||
List sub-definitions (e.g., methods in class).
|
List sub-definitions (e.g., methods in class).
|
||||||
|
|
||||||
@@ -365,10 +365,10 @@ class Definition(BaseDefinition):
|
|||||||
d = d.var
|
d = d.var
|
||||||
if isinstance(d, pr.Name):
|
if isinstance(d, pr.Name):
|
||||||
d = d.parent
|
d = d.parent
|
||||||
return get_definitions(d)
|
return defined_names(d)
|
||||||
|
|
||||||
|
|
||||||
def get_definitions(scope):
|
def defined_names(scope):
|
||||||
"""
|
"""
|
||||||
List sub-definitions (e.g., methods in class).
|
List sub-definitions (e.g., methods in class).
|
||||||
|
|
||||||
|
|||||||
@@ -394,7 +394,7 @@ class TestFeature(TestBase):
|
|||||||
class TestGetDefinitions(TestBase):
|
class TestGetDefinitions(TestBase):
|
||||||
|
|
||||||
def test_get_definitions_flat(self):
|
def test_get_definitions_flat(self):
|
||||||
definitions = api.get_definitions("""
|
definitions = api.defined_names("""
|
||||||
import module
|
import module
|
||||||
class Class:
|
class Class:
|
||||||
pass
|
pass
|
||||||
@@ -406,7 +406,7 @@ class TestGetDefinitions(TestBase):
|
|||||||
['module', 'Class', 'func', 'data'])
|
['module', 'Class', 'func', 'data'])
|
||||||
|
|
||||||
def test_dotted_assignment(self):
|
def test_dotted_assignment(self):
|
||||||
definitions = api.get_definitions("""
|
definitions = api.defined_names("""
|
||||||
x = Class()
|
x = Class()
|
||||||
x.y.z = None
|
x.y.z = None
|
||||||
""")
|
""")
|
||||||
@@ -414,14 +414,14 @@ class TestGetDefinitions(TestBase):
|
|||||||
['x'])
|
['x'])
|
||||||
|
|
||||||
def test_multiple_assignment(self):
|
def test_multiple_assignment(self):
|
||||||
definitions = api.get_definitions("""
|
definitions = api.defined_names("""
|
||||||
x = y = None
|
x = y = None
|
||||||
""")
|
""")
|
||||||
self.assertEqual([d.name for d in definitions],
|
self.assertEqual([d.name for d in definitions],
|
||||||
['x', 'y'])
|
['x', 'y'])
|
||||||
|
|
||||||
def test_multiple_imports(self):
|
def test_multiple_imports(self):
|
||||||
definitions = api.get_definitions("""
|
definitions = api.defined_names("""
|
||||||
from module import a, b
|
from module import a, b
|
||||||
from another_module import *
|
from another_module import *
|
||||||
""")
|
""")
|
||||||
@@ -429,7 +429,7 @@ class TestGetDefinitions(TestBase):
|
|||||||
['a', 'b'])
|
['a', 'b'])
|
||||||
|
|
||||||
def test_nested_definitions(self):
|
def test_nested_definitions(self):
|
||||||
definitions = api.get_definitions("""
|
definitions = api.defined_names("""
|
||||||
class Class:
|
class Class:
|
||||||
def f():
|
def f():
|
||||||
pass
|
pass
|
||||||
@@ -438,7 +438,7 @@ class TestGetDefinitions(TestBase):
|
|||||||
""")
|
""")
|
||||||
self.assertEqual([d.name for d in definitions],
|
self.assertEqual([d.name for d in definitions],
|
||||||
['Class'])
|
['Class'])
|
||||||
subdefinitions = definitions[0].get_definitions()
|
subdefinitions = definitions[0].defined_names()
|
||||||
self.assertEqual([d.name for d in subdefinitions],
|
self.assertEqual([d.name for d in subdefinitions],
|
||||||
['f', 'g'])
|
['f', 'g'])
|
||||||
self.assertEqual([d.full_name for d in subdefinitions],
|
self.assertEqual([d.full_name for d in subdefinitions],
|
||||||
|
|||||||
Reference in New Issue
Block a user