Skip to content

Commit

Permalink
Merge pull request #1711 from davidhalter/deprecations
Browse files Browse the repository at this point in the history
Remove Deprecations
  • Loading branch information
davidhalter committed Dec 21, 2020
2 parents fe60b5c + fa2d03a commit ce6ddb9
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 183 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Expand Up @@ -18,6 +18,7 @@ Unreleased
- Started using annotations
- Better support for the walrus operator
- Project attributes are now read accessible
- Removed all deprecations

This is likely going to be the last minor release before 1.0.

Expand Down
1 change: 1 addition & 0 deletions conftest.py
Expand Up @@ -16,6 +16,7 @@
'jedi/inference/compiled/subprocess/__main__.py',
'build/',
'test/examples',
'sith.py',
]


Expand Down
5 changes: 2 additions & 3 deletions docs/docs/api.rst
Expand Up @@ -169,6 +169,5 @@ Deprecations

The deprecation process is as follows:

1. A deprecation is announced in the next major/minor release.
2. We wait either at least a year and at least two minor releases until we
remove the deprecated functionality.
1. A deprecation is announced in any release.
2. The next major release removes the deprecated functionality.
3 changes: 1 addition & 2 deletions jedi/__init__.py
Expand Up @@ -29,8 +29,7 @@

__version__ = '0.17.2'

from jedi.api import Script, Interpreter, set_debug_function, \
preload_module, names
from jedi.api import Script, Interpreter, set_debug_function, preload_module
from jedi import settings
from jedi.api.environment import find_virtualenvs, find_system_environments, \
get_default_environment, InvalidPythonEnvironment, create_environment, \
Expand Down
99 changes: 1 addition & 98 deletions jedi/api/__init__.py
Expand Up @@ -8,7 +8,6 @@
arguments.
"""
import sys
import warnings
from pathlib import Path

import parso
Expand Down Expand Up @@ -90,51 +89,23 @@ class Script:
:param code: The source code of the current file, separated by newlines.
:type code: str
:param line: Deprecated, please use it directly on e.g. ``.complete``
:type line: int
:param column: Deprecated, please use it directly on e.g. ``.complete``
:type column: int
:param path: The path of the file in the file system, or ``''`` if
it hasn't been saved yet.
:type path: str or pathlib.Path or None
:param sys_path: Deprecated, use the project parameter.
:type sys_path: typing.List[str]
:param Environment environment: Provide a predefined :ref:`Environment <environments>`
to work with a specific Python version or virtualenv.
:param Project project: Provide a :class:`.Project` to make sure finding
references works well, because the right folder is searched. There are
also ways to modify the sys path and other things.
"""
def __init__(self, code=None, line=None, column=None, path=None,
sys_path=None, environment=None, project=None, source=None):
def __init__(self, code=None, *, path=None, environment=None, project=None):
self._orig_path = path
# An empty path (also empty string) should always result in no path.
if isinstance(path, str):
path = Path(path)

self.path = path.absolute() if path else None

if line is not None:
warnings.warn(
"Providing the line is now done in the functions themselves "
"like `Script(...).complete(line, column)`",
DeprecationWarning,
stacklevel=2
)
if column is not None:
warnings.warn(
"Providing the column is now done in the functions themselves "
"like `Script(...).complete(line, column)`",
DeprecationWarning,
stacklevel=2
)
if source is not None:
code = source
warnings.warn(
"Use the code keyword argument instead.",
DeprecationWarning,
stacklevel=2
)
if code is None:
# TODO add a better warning than the traceback!
with open(path, 'rb') as f:
Expand All @@ -143,15 +114,6 @@ def __init__(self, code=None, line=None, column=None, path=None,
if project is None:
# Load the Python grammar of the current interpreter.
project = get_default_project(None if self.path is None else self.path.parent)
# TODO deprecate and remove sys_path from the Script API.
if sys_path is not None:
project._sys_path = sys_path
warnings.warn(
"Deprecated since version 0.17.0. Use the project API instead, "
"which means Script(project=Project(dir, sys_path=sys_path)) instead.",
DeprecationWarning,
stacklevel=2
)

self._inference_state = InferenceState(
project, environment=environment, script_path=self.path
Expand All @@ -168,7 +130,6 @@ def __init__(self, code=None, line=None, column=None, path=None,
debug.speed('parsed')
self._code_lines = parso.split_lines(code, keepends=True)
self._code = code
self._pos = line, column

cache.clear_time_caches()
debug.reset_time()
Expand Down Expand Up @@ -251,14 +212,6 @@ def complete(self, line=None, column=None, *, fuzzy=False):
)
return completion.complete()

def completions(self, fuzzy=False):
warnings.warn(
"Deprecated since version 0.16.0. Use Script(...).complete instead.",
DeprecationWarning,
stacklevel=2
)
return self.complete(*self._pos, fuzzy=fuzzy)

@validate_line_column
def infer(self, line=None, column=None, *, only_stubs=False, prefer_stubs=False):
"""
Expand Down Expand Up @@ -303,25 +256,6 @@ def infer(self, line=None, column=None, *, only_stubs=False, prefer_stubs=False)
# the API.
return helpers.sorted_definitions(set(defs))

def goto_definitions(self, **kwargs):
warnings.warn(
"Deprecated since version 0.16.0. Use Script(...).infer instead.",
DeprecationWarning,
stacklevel=2
)
return self.infer(*self._pos, **kwargs)

def goto_assignments(self, follow_imports=False, follow_builtin_imports=False, **kwargs):
warnings.warn(
"Deprecated since version 0.16.0. Use Script(...).goto instead.",
DeprecationWarning,
stacklevel=2
)
return self.goto(*self._pos,
follow_imports=follow_imports,
follow_builtin_imports=follow_builtin_imports,
**kwargs)

@validate_line_column
def goto(self, line=None, column=None, *, follow_imports=False, follow_builtin_imports=False,
only_stubs=False, prefer_stubs=False):
Expand Down Expand Up @@ -452,14 +386,6 @@ def need_pydoc():
return [classes.Name(self._inference_state, name)]
return []

def usages(self, **kwargs):
warnings.warn(
"Deprecated since version 0.16.0. Use Script(...).get_references instead.",
DeprecationWarning,
stacklevel=2
)
return self.get_references(*self._pos, **kwargs)

@validate_line_column
def get_references(self, line=None, column=None, **kwargs):
"""
Expand Down Expand Up @@ -490,14 +416,6 @@ def _references(include_builtins=True, scope='project'):
return helpers.sorted_definitions(definitions)
return _references(**kwargs)

def call_signatures(self):
warnings.warn(
"Deprecated since version 0.16.0. Use Script(...).get_signatures instead.",
DeprecationWarning,
stacklevel=2
)
return self.get_signatures(*self._pos)

@validate_line_column
def get_signatures(self, line=None, column=None):
"""
Expand Down Expand Up @@ -823,21 +741,6 @@ def _get_module_context(self):
)


def names(source=None, path=None, all_scopes=False,
definitions=True, references=False, environment=None):
warnings.warn(
"Deprecated since version 0.16.0. Use Script(...).get_names instead.",
DeprecationWarning,
stacklevel=2
)

return Script(source, path=path).get_names(
all_scopes=all_scopes,
definitions=definitions,
references=references,
)


def preload_module(*modules):
"""
Preloading modules tells Jedi to load a module now, instead of lazy parsing
Expand Down
40 changes: 0 additions & 40 deletions jedi/api/classes.py
Expand Up @@ -14,7 +14,6 @@
the interesting information about all operations.
"""
import re
import warnings
from pathlib import Path
from typing import Optional

Expand Down Expand Up @@ -451,14 +450,6 @@ def goto(self, *, follow_imports=False, follow_builtin_imports=False,
return [self if n == self._name else Name(self._inference_state, n)
for n in names]

def goto_assignments(self, **kwargs):
warnings.warn(
"Deprecated since version 0.16.0. Use .goto.",
DeprecationWarning,
stacklevel=2
)
return self.goto(**kwargs)

@debug.increase_indent_cm('infer on name')
def infer(self, *, only_stubs=False, prefer_stubs=False):
"""
Expand Down Expand Up @@ -495,28 +486,6 @@ def infer(self, *, only_stubs=False, prefer_stubs=False):
return [self if n == self._name else Name(self._inference_state, n)
for n in resulting_names]

@property # type: ignore[misc]
@memoize_method
def params(self):
warnings.warn(
"Deprecated since version 0.16.0. Use get_signatures()[...].params",
DeprecationWarning,
stacklevel=2
)
# Only return the first one. There might be multiple one, especially
# with overloading.
for signature in self._get_signatures():
return [
Name(self._inference_state, n)
for n in signature.get_param_names(resolve_stars=True)
]

if self.type == 'function' or self.type == 'class':
# Fallback, if no signatures were defined (which is probably by
# itself a bug).
return []
raise AttributeError('There are no params defined on this.')

def parent(self):
"""
Returns the parent scope of this identifier.
Expand Down Expand Up @@ -779,15 +748,6 @@ class Name(BaseName):
def __init__(self, inference_state, definition):
super().__init__(inference_state, definition)

@property
def desc_with_module(self):
warnings.warn(
"Deprecated since version 0.17.0. No replacement for now, maybe .full_name helps",
DeprecationWarning,
stacklevel=2
)
return "%s:%s" % (self.module_name, self.description)

@memoize_method
def defined_names(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion test/test_api/test_call_signatures.py
Expand Up @@ -253,7 +253,7 @@ def huhu(it):


def _params(Script, source, line=None, column=None):
signatures = Script(source, line, column).get_signatures()
signatures = Script(source).get_signatures(line, column)
assert len(signatures) == 1
return signatures[0].params

Expand Down
39 changes: 0 additions & 39 deletions test/test_deprecation.py

This file was deleted.

0 comments on commit ce6ddb9

Please sign in to comment.