Skip to content

Remove deprecated functions and classes #8409

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 9, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions doc/whatsnew/fragments/8409.breaking
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
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
2 changes: 0 additions & 2 deletions pylint/checkers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
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):
Expand Down Expand Up @@ -141,7 +140,6 @@ def initialize(linter: PyLinter) -> None:
"BaseTokenChecker",
"BaseRawFileChecker",
"initialize",
"MapReduceMixin",
"DeprecatedMixin",
"register_plugins",
]
32 changes: 0 additions & 32 deletions pylint/checkers/mapreduce_checker.py

This file was deleted.

52 changes: 0 additions & 52 deletions pylint/checkers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import numbers
import re
import string
import warnings
from collections import deque
from collections.abc import Iterable, Iterator
from functools import lru_cache, partial
Expand Down Expand Up @@ -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]:
Expand Down Expand Up @@ -503,25 +491,6 @@ def store_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."""

Expand Down Expand Up @@ -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.

Expand Down
9 changes: 1 addition & 8 deletions pylint/lint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,7 @@
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",
Expand All @@ -42,8 +37,6 @@
"report_total_messages_stats",
"Run",
"ArgumentPreprocessingError",
"_patch_sys_path",
"fix_import_path",
"_augment_sys_path",
"augmented_sys_path",
"discover_package_path",
Expand Down
13 changes: 0 additions & 13 deletions pylint/lint/expand_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import os
import sys
import warnings
from collections.abc import Sequence
from re import Pattern

Expand All @@ -24,18 +23,6 @@ def _is_package_cb(inner_path: str, parts: list[str]) -> bool:
)


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))
Expand Down
37 changes: 0 additions & 37 deletions pylint/lint/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@
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:
Expand Down Expand Up @@ -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 = []
Expand All @@ -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."""
Expand Down
24 changes: 0 additions & 24 deletions pylint/testutils/functional_test_file.py

This file was deleted.

2 changes: 0 additions & 2 deletions pylint/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
decoding_stream,
diff_string,
format_section,
get_global_option,
get_module_and_frameid,
get_rst_section,
get_rst_title,
Expand All @@ -41,7 +40,6 @@
"diff_string",
"FileState",
"format_section",
"get_global_option",
"get_module_and_frameid",
"get_rst_section",
"get_rst_title",
Expand Down
Loading