mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-08 14:54:47 +08:00
Make sure that jedi.names is not references anymore
This commit is contained in:
@@ -149,8 +149,9 @@ This means that in Python you can enable tab completion in a `REPL
|
|||||||
Static Analysis
|
Static Analysis
|
||||||
------------------------
|
------------------------
|
||||||
|
|
||||||
To do all forms of static analysis, please try to use ``jedi.names``. It will
|
To do all forms of static analysis, please try to use
|
||||||
return a list of names that you can use to infer types and so on.
|
``jedi.Script(...).names``. It will return a list of names that you can use to
|
||||||
|
infer types and so on.
|
||||||
|
|
||||||
|
|
||||||
Refactoring
|
Refactoring
|
||||||
|
|||||||
@@ -106,8 +106,8 @@ def Script(environment):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='session')
|
@pytest.fixture(scope='session')
|
||||||
def names(environment):
|
def names(Script):
|
||||||
return partial(jedi.names, environment=environment)
|
return lambda code, **kwargs: Script(code).names(**kwargs)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='session')
|
@pytest.fixture(scope='session')
|
||||||
|
|||||||
@@ -30,8 +30,7 @@ API Documentation
|
|||||||
The API consists of a few different parts:
|
The API consists of a few different parts:
|
||||||
|
|
||||||
- The main starting points for complete/goto: :class:`.Script` and :class:`.Interpreter`
|
- The main starting points for complete/goto: :class:`.Script` and :class:`.Interpreter`
|
||||||
- Helpful functions: :func:`.names`, :func:`.preload_module` and
|
- Helpful functions: :func:`.preload_module` and :func:`.set_debug_function`
|
||||||
:func:`.set_debug_function`
|
|
||||||
- :ref:`API Result Classes <api-classes>`
|
- :ref:`API Result Classes <api-classes>`
|
||||||
- :ref:`Python Versions/Virtualenv Support <environments>` with functions like
|
- :ref:`Python Versions/Virtualenv Support <environments>` with functions like
|
||||||
:func:`.find_system_environments` and :func:`.find_virtualenvs`
|
:func:`.find_system_environments` and :func:`.find_virtualenvs`
|
||||||
@@ -47,7 +46,6 @@ Static Analysis Interface
|
|||||||
:members:
|
:members:
|
||||||
.. autoclass:: jedi.Interpreter
|
.. autoclass:: jedi.Interpreter
|
||||||
:members:
|
:members:
|
||||||
.. autofunction:: jedi.names
|
|
||||||
.. autofunction:: jedi.preload_module
|
.. autofunction:: jedi.preload_module
|
||||||
.. autofunction:: jedi.set_debug_function
|
.. autofunction:: jedi.set_debug_function
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ Features and Caveats
|
|||||||
Jedi obviously supports autocompletion. It's also possible to get it working in
|
Jedi obviously supports autocompletion. It's also possible to get it working in
|
||||||
(:ref:`your REPL (IPython, etc.) <repl-completion>`).
|
(:ref:`your REPL (IPython, etc.) <repl-completion>`).
|
||||||
|
|
||||||
Static analysis is also possible by using the command ``jedi.names``.
|
Static analysis is also possible by using ``jedi.Script(...).names``.
|
||||||
|
|
||||||
Jedi would in theory support refactoring, but we have never publicized it,
|
Jedi would in theory support refactoring, but we have never publicized it,
|
||||||
because it's not production ready. If you're interested in helping out here,
|
because it's not production ready. If you're interested in helping out here,
|
||||||
|
|||||||
@@ -289,11 +289,11 @@ def test_parent_on_completion(Script):
|
|||||||
assert parent.type == 'class'
|
assert parent.type == 'class'
|
||||||
|
|
||||||
|
|
||||||
def test_parent_on_comprehension():
|
def test_parent_on_comprehension(Script):
|
||||||
ns = jedi.names('''\
|
ns = Script('''\
|
||||||
def spam():
|
def spam():
|
||||||
return [i for i in range(5)]
|
return [i for i in range(5)]
|
||||||
''', all_scopes=True)
|
''').names(all_scopes=True)
|
||||||
|
|
||||||
assert [name.name for name in ns] == ['spam', 'i']
|
assert [name.name for name in ns] == ['spam', 'i']
|
||||||
|
|
||||||
|
|||||||
@@ -139,12 +139,12 @@ def test_follow_imports(names):
|
|||||||
|
|
||||||
|
|
||||||
def test_names_twice(names):
|
def test_names_twice(names):
|
||||||
source = dedent('''
|
code = dedent('''
|
||||||
def lol():
|
def lol():
|
||||||
pass
|
pass
|
||||||
''')
|
''')
|
||||||
|
|
||||||
defs = names(source=source)
|
defs = names(code)
|
||||||
assert defs[0].defined_names() == []
|
assert defs[0].defined_names() == []
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -71,7 +71,8 @@ class TestFullDefinedName(TestCase):
|
|||||||
self.environment = environment
|
self.environment = environment
|
||||||
|
|
||||||
def check(self, source, desired):
|
def check(self, source, desired):
|
||||||
definitions = jedi.names(textwrap.dedent(source), environment=self.environment)
|
script = jedi.Script(textwrap.dedent(source), environment=self.environment)
|
||||||
|
definitions = script.names()
|
||||||
full_names = [d.full_name for d in definitions]
|
full_names = [d.full_name for d in definitions]
|
||||||
self.assertEqual(full_names, desired)
|
self.assertEqual(full_names, desired)
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,14 @@
|
|||||||
from textwrap import dedent
|
from textwrap import dedent
|
||||||
|
|
||||||
from jedi import names
|
|
||||||
from jedi.inference import helpers
|
from jedi.inference import helpers
|
||||||
|
|
||||||
|
|
||||||
def test_call_of_leaf_in_brackets(environment):
|
def test_call_of_leaf_in_brackets(Script):
|
||||||
s = dedent("""
|
s = dedent("""
|
||||||
x = 1
|
x = 1
|
||||||
type(x)
|
type(x)
|
||||||
""")
|
""")
|
||||||
last_x = names(s, references=True, definitions=False, environment=environment)[-1]
|
last_x = Script(s).names(references=True, definitions=False)[-1]
|
||||||
name = last_x._name.tree_name
|
name = last_x._name.tree_name
|
||||||
|
|
||||||
call = helpers.call_of_leaf(name)
|
call = helpers.call_of_leaf(name)
|
||||||
|
|||||||
Reference in New Issue
Block a user