From b2ab82a1daed9a9cc2062272e15dee7e6648e6b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Noord?= <13665637+DanielNoord@users.noreply.github.com> Date: Thu, 9 Mar 2023 11:51:17 +0100 Subject: Remove deprecated functions and classes (#8409) Co-authored-by: Pierre Sassoulas --- doc/whatsnew/fragments/8409.breaking | 24 +++++++++ pylint/checkers/__init__.py | 2 - pylint/checkers/mapreduce_checker.py | 32 ------------ pylint/checkers/utils.py | 52 -------------------- pylint/lint/__init__.py | 9 +--- pylint/lint/expand_modules.py | 13 ----- pylint/lint/utils.py | 37 -------------- pylint/testutils/functional_test_file.py | 24 --------- pylint/utils/__init__.py | 2 - pylint/utils/utils.py | 84 +------------------------------- tests/checkers/unittest_utils.py | 25 ---------- tests/config/test_deprecations.py | 33 ------------- tests/lint/unittest_lint.py | 9 ---- tests/test_deprecation.py | 42 ---------------- 14 files changed, 26 insertions(+), 362 deletions(-) create mode 100644 doc/whatsnew/fragments/8409.breaking delete mode 100644 pylint/checkers/mapreduce_checker.py delete mode 100644 pylint/testutils/functional_test_file.py delete mode 100644 tests/config/test_deprecations.py delete mode 100644 tests/test_deprecation.py diff --git a/doc/whatsnew/fragments/8409.breaking b/doc/whatsnew/fragments/8409.breaking new file mode 100644 index 000000000..415dec9cf --- /dev/null +++ b/doc/whatsnew/fragments/8409.breaking @@ -0,0 +1,24 @@ +A number of old utility functions and classes have been removed: + +``MapReduceMixin``: To make a checker reduce map data simply implement +``get_map_data`` and ``reduce_map_data``. + +``is_inside_lambda``: Use ``utils.get_node_first_ancestor_of_type(x, nodes.Lambda)`` + +``check_messages``: Use ``utils.only_required_for_messages`` + +``is_class_subscriptable_pep585_with_postponed_evaluation_enabled``: Use +``is_postponed_evaluation_enabled(node)`` and ``is_node_in_type_annotation_context(node)`` + +``get_python_path``: assumption that there's always an __init__.py is not true since +python 3.3 and is causing problems, particularly with PEP 420. Use ``discover_package_path`` +and pass source root(s). + +``fix_import_path``: Use ``augmented_sys_path`` and pass additional ``sys.path`` +entries as an argument obtained from ``discover_package_path``. + +``get_global_option``: Use ``checker.linter.config`` to get all global options. + +Related private objects have been removed as well. + +Refs #8409 diff --git a/pylint/checkers/__init__.py b/pylint/checkers/__init__.py index ed641d8e5..8f55d214f 100644 --- a/pylint/checkers/__init__.py +++ b/pylint/checkers/__init__.py @@ -51,7 +51,6 @@ from pylint.checkers.base_checker import ( BaseTokenChecker, ) from pylint.checkers.deprecated import DeprecatedMixin -from pylint.checkers.mapreduce_checker import MapReduceMixin from pylint.utils import LinterStats, diff_string, register_plugins if sys.version_info >= (3, 8): @@ -141,7 +140,6 @@ __all__ = [ "BaseTokenChecker", "BaseRawFileChecker", "initialize", - "MapReduceMixin", "DeprecatedMixin", "register_plugins", ] diff --git a/pylint/checkers/mapreduce_checker.py b/pylint/checkers/mapreduce_checker.py deleted file mode 100644 index 96e86d7c0..000000000 --- a/pylint/checkers/mapreduce_checker.py +++ /dev/null @@ -1,32 +0,0 @@ -# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html -# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE -# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt - -from __future__ import annotations - -import abc -import warnings -from typing import TYPE_CHECKING, Any - -if TYPE_CHECKING: - from pylint.lint import PyLinter - - -class MapReduceMixin(metaclass=abc.ABCMeta): - """A mixin design to allow multi-process/threaded runs of a Checker.""" - - def __init__(self) -> None: - warnings.warn( - "MapReduceMixin has been deprecated and will be removed in pylint 3.0. " - "To make a checker reduce map data simply implement get_map_data and reduce_map_data.", - DeprecationWarning, - stacklevel=2, - ) - - @abc.abstractmethod - def get_map_data(self) -> Any: - """Returns merge-able/reducible data that will be examined.""" - - @abc.abstractmethod - def reduce_map_data(self, linter: PyLinter, data: list[Any]) -> None: - """For a given Checker, receives data for all mapped runs.""" diff --git a/pylint/checkers/utils.py b/pylint/checkers/utils.py index 9f1ce93fe..d1d77dc0a 100644 --- a/pylint/checkers/utils.py +++ b/pylint/checkers/utils.py @@ -12,7 +12,6 @@ import itertools import numbers import re import string -import warnings from collections import deque from collections.abc import Iterable, Iterator from functools import lru_cache, partial @@ -247,17 +246,6 @@ class InferredTypeError(Exception): pass -def is_inside_lambda(node: nodes.NodeNG) -> bool: - """Return whether the given node is inside a lambda.""" - warnings.warn( - "utils.is_inside_lambda will be removed in favour of calling " - "utils.get_node_first_ancestor_of_type(x, nodes.Lambda) in pylint 3.0", - DeprecationWarning, - stacklevel=2, - ) - return any(isinstance(parent, nodes.Lambda) for parent in node.node_ancestors()) - - def get_all_elements( node: nodes.NodeNG, ) -> Iterable[nodes.NodeNG]: @@ -503,25 +491,6 @@ def only_required_for_messages( return store_messages -def check_messages( - *messages: str, -) -> Callable[ - [AstCallbackMethod[_CheckerT, _NodeT]], AstCallbackMethod[_CheckerT, _NodeT] -]: - """Kept for backwards compatibility, deprecated. - - Use only_required_for_messages instead, which conveys the intent of the decorator much clearer. - """ - warnings.warn( - "utils.check_messages will be removed in favour of calling " - "utils.only_required_for_messages in pylint 3.0", - DeprecationWarning, - stacklevel=2, - ) - - return only_required_for_messages(*messages) - - class IncompleteFormatString(Exception): """A format string ended in the middle of a format specifier.""" @@ -1570,27 +1539,6 @@ def is_postponed_evaluation_enabled(node: nodes.NodeNG) -> bool: return "annotations" in module.future_imports -def is_class_subscriptable_pep585_with_postponed_evaluation_enabled( - value: nodes.ClassDef, node: nodes.NodeNG -) -> bool: - """Check if class is subscriptable with PEP 585 and - postponed evaluation enabled. - """ - warnings.warn( - "'is_class_subscriptable_pep585_with_postponed_evaluation_enabled' has been " - "deprecated and will be removed in pylint 3.0. " - "Use 'is_postponed_evaluation_enabled(node) and " - "is_node_in_type_annotation_context(node)' instead.", - DeprecationWarning, - stacklevel=2, - ) - return ( - is_postponed_evaluation_enabled(node) - and value.qname() in SUBSCRIPTABLE_CLASSES_PEP585 - and is_node_in_type_annotation_context(node) - ) - - def is_node_in_type_annotation_context(node: nodes.NodeNG) -> bool: """Check if node is in type annotation context. diff --git a/pylint/lint/__init__.py b/pylint/lint/__init__.py index 573d9c262..cd89c43f8 100644 --- a/pylint/lint/__init__.py +++ b/pylint/lint/__init__.py @@ -27,12 +27,7 @@ from pylint.lint.report_functions import ( report_total_messages_stats, ) from pylint.lint.run import Run -from pylint.lint.utils import ( - _augment_sys_path, - _patch_sys_path, - augmented_sys_path, - fix_import_path, -) +from pylint.lint.utils import _augment_sys_path, augmented_sys_path __all__ = [ "check_parallel", @@ -42,8 +37,6 @@ __all__ = [ "report_total_messages_stats", "Run", "ArgumentPreprocessingError", - "_patch_sys_path", - "fix_import_path", "_augment_sys_path", "augmented_sys_path", "discover_package_path", diff --git a/pylint/lint/expand_modules.py b/pylint/lint/expand_modules.py index bb25986e4..6ee96e4bd 100644 --- a/pylint/lint/expand_modules.py +++ b/pylint/lint/expand_modules.py @@ -6,7 +6,6 @@ from __future__ import annotations import os import sys -import warnings from collections.abc import Sequence from re import Pattern @@ -24,18 +23,6 @@ def _modpath_from_file(filename: str, is_namespace: bool, path: list[str]) -> li ) -def get_python_path(filepath: str) -> str: - # TODO: Remove deprecated function - warnings.warn( - "get_python_path has been deprecated because assumption that there's always an __init__.py " - "is not true since python 3.3 and is causing problems, particularly with PEP 420." - "Use discover_package_path and pass source root(s).", - DeprecationWarning, - stacklevel=2, - ) - return discover_package_path(filepath, []) - - def discover_package_path(modulepath: str, source_roots: Sequence[str]) -> str: """Discover package path from one its modules and source roots.""" dirname = os.path.realpath(os.path.expanduser(modulepath)) diff --git a/pylint/lint/utils.py b/pylint/lint/utils.py index 950c94b85..f0c841f62 100644 --- a/pylint/lint/utils.py +++ b/pylint/lint/utils.py @@ -7,13 +7,11 @@ from __future__ import annotations import contextlib import sys import traceback -import warnings from collections.abc import Iterator, Sequence from datetime import datetime from pathlib import Path from pylint.constants import PYLINT_HOME -from pylint.lint.expand_modules import discover_package_path def prepare_crash_report(ex: Exception, filepath: str, crash_file_path: str) -> Path: @@ -73,19 +71,6 @@ def get_fatal_error_message(filepath: str, issue_template_path: Path) -> str: ) -def _patch_sys_path(args: Sequence[str]) -> list[str]: - # TODO: Remove deprecated function - warnings.warn( - "_patch_sys_path has been deprecated because it relies on auto-magic package path " - "discovery which is implemented by get_python_path that is deprecated. " - "Use _augment_sys_path and pass additional sys.path entries as an argument obtained from " - "discover_package_path.", - DeprecationWarning, - stacklevel=2, - ) - return _augment_sys_path([discover_package_path(arg, []) for arg in args]) - - def _augment_sys_path(additional_paths: Sequence[str]) -> list[str]: original = list(sys.path) changes = [] @@ -99,28 +84,6 @@ def _augment_sys_path(additional_paths: Sequence[str]) -> list[str]: return original -@contextlib.contextmanager -def fix_import_path(args: Sequence[str]) -> Iterator[None]: - """Prepare 'sys.path' for running the linter checks. - - Within this context, each of the given arguments is importable. - Paths are added to 'sys.path' in corresponding order to the arguments. - We avoid adding duplicate directories to sys.path. - `sys.path` is reset to its original value upon exiting this context. - """ - # TODO: Remove deprecated function - warnings.warn( - "fix_import_path has been deprecated because it relies on auto-magic package path " - "discovery which is implemented by get_python_path that is deprecated. " - "Use augmented_sys_path and pass additional sys.path entries as an argument obtained from " - "discover_package_path.", - DeprecationWarning, - stacklevel=2, - ) - with augmented_sys_path([discover_package_path(arg, []) for arg in args]): - yield - - @contextlib.contextmanager def augmented_sys_path(additional_paths: Sequence[str]) -> Iterator[None]: """Augment 'sys.path' by adding non-existent entries from additional_paths.""" diff --git a/pylint/testutils/functional_test_file.py b/pylint/testutils/functional_test_file.py deleted file mode 100644 index e2bd7f59b..000000000 --- a/pylint/testutils/functional_test_file.py +++ /dev/null @@ -1,24 +0,0 @@ -# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html -# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE -# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt - -__all__ = [ - "FunctionalTestFile", - "NoFileError", - "parse_python_version", -] - -import warnings - -from pylint.testutils.functional import ( - FunctionalTestFile, - NoFileError, - parse_python_version, -) - -warnings.warn( - "'pylint.testutils.functional_test_file' will be accessible from" - " the 'pylint.testutils.functional' namespace in pylint 3.0.", - DeprecationWarning, - stacklevel=2, -) diff --git a/pylint/utils/__init__.py b/pylint/utils/__init__.py index bc5011db9..ccf4079c4 100644 --- a/pylint/utils/__init__.py +++ b/pylint/utils/__init__.py @@ -20,7 +20,6 @@ from pylint.utils.utils import ( decoding_stream, diff_string, format_section, - get_global_option, get_module_and_frameid, get_rst_section, get_rst_title, @@ -41,7 +40,6 @@ __all__ = [ "diff_string", "FileState", "format_section", - "get_global_option", "get_module_and_frameid", "get_rst_section", "get_rst_title", diff --git a/pylint/utils/utils.py b/pylint/utils/utils.py index 054d307bc..2bdc529cc 100644 --- a/pylint/utils/utils.py +++ b/pylint/utils/utils.py @@ -24,17 +24,7 @@ import tokenize import warnings from collections.abc import Sequence from io import BufferedReader, BytesIO -from typing import ( - TYPE_CHECKING, - Any, - List, - Pattern, - TextIO, - Tuple, - TypeVar, - Union, - overload, -) +from typing import TYPE_CHECKING, Any, List, Pattern, TextIO, Tuple, TypeVar, Union from astroid import Module, modutils, nodes @@ -47,7 +37,6 @@ else: from typing_extensions import Literal if TYPE_CHECKING: - from pylint.checkers.base_checker import BaseChecker from pylint.lint import PyLinter DEFAULT_LINE_LENGTH = 79 @@ -215,77 +204,6 @@ def register_plugins(linter: PyLinter, directory: str) -> None: imported[base] = 1 -@overload -def get_global_option( - checker: BaseChecker, option: GLOBAL_OPTION_BOOL, default: bool | None = ... -) -> bool: - ... - - -@overload -def get_global_option( - checker: BaseChecker, option: GLOBAL_OPTION_INT, default: int | None = ... -) -> int: - ... - - -@overload -def get_global_option( - checker: BaseChecker, - option: GLOBAL_OPTION_LIST, - default: list[str] | None = ..., -) -> list[str]: - ... - - -@overload -def get_global_option( - checker: BaseChecker, - option: GLOBAL_OPTION_PATTERN, - default: Pattern[str] | None = ..., -) -> Pattern[str]: - ... - - -@overload -def get_global_option( - checker: BaseChecker, - option: GLOBAL_OPTION_PATTERN_LIST, - default: list[Pattern[str]] | None = ..., -) -> list[Pattern[str]]: - ... - - -@overload -def get_global_option( - checker: BaseChecker, - option: GLOBAL_OPTION_TUPLE_INT, - default: tuple[int, ...] | None = ..., -) -> tuple[int, ...]: - ... - - -def get_global_option( - checker: BaseChecker, - option: GLOBAL_OPTION_NAMES, - default: T_GlobalOptionReturnTypes | None = None, # pylint: disable=unused-argument -) -> T_GlobalOptionReturnTypes | None | Any: - """DEPRECATED: Retrieve an option defined by the given *checker* or - by all known option providers. - - It will look in the list of all options providers - until the given *option* will be found. - If the option wasn't found, the *default* value will be returned. - """ - warnings.warn( - "get_global_option has been deprecated. You can use " - "checker.linter.config to get all global options instead.", - DeprecationWarning, - stacklevel=2, - ) - return getattr(checker.linter.config, option.replace("-", "_")) - - def _splitstrip(string: str, sep: str = ",") -> list[str]: """Return a list of stripped string by splitting the string given as argument on `sep` (',' by default), empty strings are discarded. diff --git a/tests/checkers/unittest_utils.py b/tests/checkers/unittest_utils.py index b2cbcb590..231fed555 100644 --- a/tests/checkers/unittest_utils.py +++ b/tests/checkers/unittest_utils.py @@ -11,7 +11,6 @@ import pytest from astroid import nodes from pylint.checkers import utils -from pylint.checkers.base_checker import BaseChecker @pytest.mark.parametrize( @@ -469,30 +468,6 @@ def test_is_empty_literal() -> None: assert not utils.is_empty_str_literal(not_empty_string_node.value) -def test_deprecation_is_inside_lambda() -> None: - """Test that is_inside_lambda is throwing a DeprecationWarning.""" - with pytest.warns(DeprecationWarning) as records: - utils.is_inside_lambda(nodes.NodeNG()) - assert len(records) == 1 - - -def test_deprecation_check_messages() -> None: - with pytest.warns(DeprecationWarning) as records: - - class Checker(BaseChecker): # pylint: disable=unused-variable - @utils.check_messages("my-message") - def visit_assname(self, node: nodes.NodeNG) -> None: - pass - - deprecationMessage = ( - "utils.check_messages will be removed in " - "favour of calling utils.only_required_for_messages in pylint 3.0" - ) - - assert len(records) == 1 - assert records[0].message.args[0] == deprecationMessage - - def test_is_typing_member() -> None: code = astroid.extract_node( """ diff --git a/tests/config/test_deprecations.py b/tests/config/test_deprecations.py deleted file mode 100644 index 052ade9df..000000000 --- a/tests/config/test_deprecations.py +++ /dev/null @@ -1,33 +0,0 @@ -# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html -# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE -# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt - -"""Test for deprecation warnings in the config module.""" - - -import pytest - -from pylint.checkers import BaseChecker -from pylint.lint import PyLinter -from pylint.utils import get_global_option - - -class SampleChecker(BaseChecker): - options = (("test-opt", {"action": "store_true", "help": "help message"}),) - - -class TestDeprecationArgumentsManager: - """Tests for deprecation warnings in the ArgumentsManager class.""" - - linter = PyLinter() - - @classmethod - def setup_class(cls) -> None: - checker = SampleChecker(cls.linter) - cls.linter.register_checker(checker) - - def test_get_global_option(self) -> None: - """Test that get_global_option emits a DeprecationWarning.""" - checker = BaseChecker(self.linter) - with pytest.warns(DeprecationWarning): - get_global_option(checker, "test-opt") # type: ignore[call-overload] diff --git a/tests/lint/unittest_lint.py b/tests/lint/unittest_lint.py index 9f7c20ee0..4808151b8 100644 --- a/tests/lint/unittest_lint.py +++ b/tests/lint/unittest_lint.py @@ -115,15 +115,6 @@ def fake_path() -> Iterator[list[str]]: sys.path[:] = orig -def test_deprecated() -> None: - """Test that fix_import_path() and get_python_path() are deprecated""" - with tempdir(): - create_files(["__init__.py"]) - with pytest.deprecated_call(): - with lint.fix_import_path([""]): - expand_modules.get_python_path("__init__.py") - - def test_no_args(fake_path: list[str]) -> None: with lint.augmented_sys_path([]): assert sys.path == fake_path diff --git a/tests/test_deprecation.py b/tests/test_deprecation.py deleted file mode 100644 index 3d3cabf0a..000000000 --- a/tests/test_deprecation.py +++ /dev/null @@ -1,42 +0,0 @@ -# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html -# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE -# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt - -"""Check deprecation across the codebase.""" - -from __future__ import annotations - -from typing import Any - -import pytest - -from pylint import lint -from pylint.checkers.mapreduce_checker import MapReduceMixin -from pylint.lint import PyLinter - - -def test_mapreducemixin() -> None: - """Test that MapReduceMixin has been deprecated correctly.""" - - class MyChecker(MapReduceMixin): - def get_map_data(self) -> Any: - ... - - def reduce_map_data(self, linter: PyLinter, data: list[Any]) -> None: - ... - - with pytest.warns(DeprecationWarning): - MyChecker() - - -def test_patch_sys_path() -> None: - """Test that _patch_sys_path() is deprecated""" - with pytest.deprecated_call(): - lint._patch_sys_path([]) - - -def test_fix_import_path() -> None: - """Test that fix_import_path() is deprecated""" - with pytest.deprecated_call(): - with lint.fix_import_path([]): - pass -- cgit v1.2.1