From dbb61357c314467859f105cad9f16e043afb5eb2 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Fri, 20 Dec 2019 18:04:47 +0100 Subject: [PATCH] Make sure that jedi.names is not references anymore --- README.rst | 5 +++-- conftest.py | 4 ++-- docs/docs/api.rst | 4 +--- docs/docs/features.rst | 2 +- test/test_api/test_classes.py | 6 +++--- test/test_api/test_defined_names.py | 4 ++-- test/test_api/test_full_name.py | 3 ++- test/test_inference/test_helpers.py | 5 ++--- 8 files changed, 16 insertions(+), 17 deletions(-) diff --git a/README.rst b/README.rst index d2cd3556..252cd48c 100644 --- a/README.rst +++ b/README.rst @@ -149,8 +149,9 @@ This means that in Python you can enable tab completion in a `REPL Static Analysis ------------------------ -To do all forms of static analysis, please try to use ``jedi.names``. It will -return a list of names that you can use to infer types and so on. +To do all forms of static analysis, please try to use +``jedi.Script(...).names``. It will return a list of names that you can use to +infer types and so on. Refactoring diff --git a/conftest.py b/conftest.py index 35aa6073..e6d8046c 100644 --- a/conftest.py +++ b/conftest.py @@ -106,8 +106,8 @@ def Script(environment): @pytest.fixture(scope='session') -def names(environment): - return partial(jedi.names, environment=environment) +def names(Script): + return lambda code, **kwargs: Script(code).names(**kwargs) @pytest.fixture(scope='session') diff --git a/docs/docs/api.rst b/docs/docs/api.rst index a3d6404f..d0073587 100644 --- a/docs/docs/api.rst +++ b/docs/docs/api.rst @@ -30,8 +30,7 @@ API Documentation The API consists of a few different parts: - The main starting points for complete/goto: :class:`.Script` and :class:`.Interpreter` -- Helpful functions: :func:`.names`, :func:`.preload_module` and - :func:`.set_debug_function` +- Helpful functions: :func:`.preload_module` and :func:`.set_debug_function` - :ref:`API Result Classes ` - :ref:`Python Versions/Virtualenv Support ` with functions like :func:`.find_system_environments` and :func:`.find_virtualenvs` @@ -47,7 +46,6 @@ Static Analysis Interface :members: .. autoclass:: jedi.Interpreter :members: -.. autofunction:: jedi.names .. autofunction:: jedi.preload_module .. autofunction:: jedi.set_debug_function diff --git a/docs/docs/features.rst b/docs/docs/features.rst index 54e1435a..693e3cdd 100644 --- a/docs/docs/features.rst +++ b/docs/docs/features.rst @@ -6,7 +6,7 @@ Features and Caveats Jedi obviously supports autocompletion. It's also possible to get it working in (:ref:`your REPL (IPython, etc.) `). -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, because it's not production ready. If you're interested in helping out here, diff --git a/test/test_api/test_classes.py b/test/test_api/test_classes.py index a976db73..7e46127a 100644 --- a/test/test_api/test_classes.py +++ b/test/test_api/test_classes.py @@ -289,11 +289,11 @@ def test_parent_on_completion(Script): assert parent.type == 'class' -def test_parent_on_comprehension(): - ns = jedi.names('''\ +def test_parent_on_comprehension(Script): + ns = Script('''\ def spam(): return [i for i in range(5)] - ''', all_scopes=True) + ''').names(all_scopes=True) assert [name.name for name in ns] == ['spam', 'i'] diff --git a/test/test_api/test_defined_names.py b/test/test_api/test_defined_names.py index 6633a04f..f037ca4b 100644 --- a/test/test_api/test_defined_names.py +++ b/test/test_api/test_defined_names.py @@ -139,12 +139,12 @@ def test_follow_imports(names): def test_names_twice(names): - source = dedent(''' + code = dedent(''' def lol(): pass ''') - defs = names(source=source) + defs = names(code) assert defs[0].defined_names() == [] diff --git a/test/test_api/test_full_name.py b/test/test_api/test_full_name.py index e63b6d8d..3c1f485a 100644 --- a/test/test_api/test_full_name.py +++ b/test/test_api/test_full_name.py @@ -71,7 +71,8 @@ class TestFullDefinedName(TestCase): self.environment = environment 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] self.assertEqual(full_names, desired) diff --git a/test/test_inference/test_helpers.py b/test/test_inference/test_helpers.py index adfb4221..03a54eb8 100644 --- a/test/test_inference/test_helpers.py +++ b/test/test_inference/test_helpers.py @@ -1,15 +1,14 @@ from textwrap import dedent -from jedi import names from jedi.inference import helpers -def test_call_of_leaf_in_brackets(environment): +def test_call_of_leaf_in_brackets(Script): s = dedent(""" x = 1 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 call = helpers.call_of_leaf(name)