diff options
author | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2023-03-08 21:39:23 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-08 21:39:23 +0100 |
commit | 358264aaf622505f6d2e8bc699618382981a078c (patch) | |
tree | 0395141b74b097cd0f55b1b97d26b9e2a7d20175 /pylint | |
parent | 3318aa0c5877abd9e9d2361f8a21b8880b7a052d (diff) | |
download | pylint-git-358264aaf622505f6d2e8bc699618382981a078c.tar.gz |
[__implements__] Remove everything related to the rejected PEP245 (#8404)
Diffstat (limited to 'pylint')
-rw-r--r-- | pylint/checkers/base_checker.py | 31 | ||||
-rw-r--r-- | pylint/interfaces.py | 102 | ||||
-rw-r--r-- | pylint/lint/pylinter.py | 32 | ||||
-rw-r--r-- | pylint/pyreverse/diagrams.py | 7 | ||||
-rw-r--r-- | pylint/pyreverse/inspector.py | 45 | ||||
-rw-r--r-- | pylint/reporters/base_reporter.py | 8 |
6 files changed, 8 insertions, 217 deletions
diff --git a/pylint/checkers/base_checker.py b/pylint/checkers/base_checker.py index d6172fb42..b75cc6dbc 100644 --- a/pylint/checkers/base_checker.py +++ b/pylint/checkers/base_checker.py @@ -6,7 +6,6 @@ from __future__ import annotations import abc import functools -import warnings from collections.abc import Iterable, Sequence from inspect import cleandoc from tokenize import TokenInfo @@ -17,7 +16,7 @@ from astroid import nodes from pylint.config.arguments_provider import _ArgumentsProvider from pylint.constants import _MSG_ORDER, MAIN_CHECKER_NAME, WarningScope from pylint.exceptions import InvalidMessageError -from pylint.interfaces import Confidence, IRawChecker, ITokenChecker, implements +from pylint.interfaces import Confidence from pylint.message.message_definition import MessageDefinition from pylint.typing import ( ExtraMessageOptions, @@ -47,18 +46,9 @@ class BaseChecker(_ArgumentsProvider): def __init__(self, linter: PyLinter) -> None: """Checker instances should have the linter as argument.""" - if getattr(self, "__implements__", None): - warnings.warn( - "Using the __implements__ inheritance pattern for BaseChecker is no " - "longer supported. Child classes should only inherit BaseChecker or any " - "of the other checker types from pylint.checkers.", - DeprecationWarning, - stacklevel=2, - ) if self.name is not None: self.name = self.name.lower() self.linter = linter - _ArgumentsProvider.__init__(self, linter) def __gt__(self, other: Any) -> bool: @@ -191,21 +181,10 @@ class BaseChecker(_ArgumentsProvider): def create_message_definition_from_tuple( self, msgid: str, msg_tuple: MessageDefinitionTuple ) -> MessageDefinition: - with warnings.catch_warnings(): - warnings.filterwarnings("ignore", category=DeprecationWarning) - if isinstance(self, (BaseTokenChecker, BaseRawFileChecker)): - default_scope = WarningScope.LINE - # TODO: 3.0: Remove deprecated if-statement - elif implements(self, (IRawChecker, ITokenChecker)): - warnings.warn( # pragma: no cover - "Checkers should subclass BaseTokenChecker or BaseRawFileChecker " - "instead of using the __implements__ mechanism. Use of __implements__ " - "will no longer be supported in pylint 3.0", - DeprecationWarning, - ) - default_scope = WarningScope.LINE # pragma: no cover - else: - default_scope = WarningScope.NODE + if isinstance(self, (BaseTokenChecker, BaseRawFileChecker)): + default_scope = WarningScope.LINE + else: + default_scope = WarningScope.NODE options: ExtraMessageOptions = {} if len(msg_tuple) == 4: (msg, symbol, descr, options) = msg_tuple # type: ignore[misc] diff --git a/pylint/interfaces.py b/pylint/interfaces.py index 221084fab..eef2b728b 100644 --- a/pylint/interfaces.py +++ b/pylint/interfaces.py @@ -2,27 +2,11 @@ # For details: https://github.com/PyCQA/pylint/blob/main/LICENSE # Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt -"""Interfaces for Pylint objects.""" - from __future__ import annotations -import warnings -from tokenize import TokenInfo -from typing import TYPE_CHECKING, NamedTuple - -from astroid import nodes - -if TYPE_CHECKING: - from pylint.checkers import BaseChecker - from pylint.message import Message - from pylint.reporters.ureports.nodes import Section +from typing import NamedTuple __all__ = ( - "IRawChecker", - "IAstroidChecker", - "ITokenChecker", - "IReporter", - "IChecker", "HIGH", "CONTROL_FLOW", "INFERENCE", @@ -51,87 +35,3 @@ UNDEFINED = Confidence("UNDEFINED", "Warning without any associated confidence l CONFIDENCE_LEVELS = [HIGH, CONTROL_FLOW, INFERENCE, INFERENCE_FAILURE, UNDEFINED] CONFIDENCE_LEVEL_NAMES = [i.name for i in CONFIDENCE_LEVELS] - - -class Interface: - """Base class for interfaces.""" - - def __init__(self) -> None: - warnings.warn( - "Interface and all of its subclasses have been deprecated " - "and will be removed in pylint 3.0.", - DeprecationWarning, - stacklevel=2, - ) - - @classmethod - def is_implemented_by( - cls: type[Interface] | tuple[type[Interface], ...], instance: BaseChecker - ) -> bool: - with warnings.catch_warnings(): - warnings.filterwarnings("ignore", category=DeprecationWarning) - return implements(instance, cls) - - -def implements( - obj: BaseChecker, - interface: type[Interface] | tuple[type[Interface], ...], -) -> bool: - """Does the given object (maybe an instance or class) implement the interface.""" - # TODO: 3.0: Remove deprecated function - warnings.warn( - "implements has been deprecated in favour of using basic " - "inheritance patterns without using __implements__.", - DeprecationWarning, - stacklevel=2, - ) - implements_ = getattr(obj, "__implements__", ()) - if not isinstance(implements_, (list, tuple)): - implements_ = (implements_,) - return any(issubclass(i, interface) for i in implements_) - - -class IChecker(Interface): - """Base interface, to be used only for sub interfaces definition.""" - - def open(self) -> None: - """Called before visiting project (i.e. set of modules).""" - - def close(self) -> None: - """Called after visiting project (i.e. set of modules).""" - - -class IRawChecker(IChecker): - """Interface for checker which need to parse the raw file.""" - - def process_module(self, node: nodes.Module) -> None: - """Process a module. - - The module's content is accessible via ``astroid.stream`` - """ - - -class ITokenChecker(IChecker): - """Interface for checkers that need access to the token list.""" - - def process_tokens(self, tokens: list[TokenInfo]) -> None: - """Process a module. - - Tokens is a list of all source code tokens in the file. - """ - - -class IAstroidChecker(IChecker): - """Interface for checker which prefers receive events according to - statement type. - """ - - -class IReporter(Interface): - """Reporter collect messages and display results encapsulated in a layout.""" - - def handle_message(self, msg: Message) -> None: - """Handle the given message object.""" - - def display_reports(self, layout: Section) -> None: - """Display results encapsulated in the layout tree.""" diff --git a/pylint/lint/pylinter.py b/pylint/lint/pylinter.py index b35867eae..143ad5c08 100644 --- a/pylint/lint/pylinter.py +++ b/pylint/lint/pylinter.py @@ -957,41 +957,9 @@ class PyLinter( tokencheckers = [ c for c in _checkers if isinstance(c, checkers.BaseTokenChecker) ] - # TODO: 3.0: Remove deprecated for-loop - for c in _checkers: - with warnings.catch_warnings(): - warnings.filterwarnings("ignore", category=DeprecationWarning) - if ( - interfaces.implements(c, interfaces.ITokenChecker) - and c not in tokencheckers - and c is not self - ): - tokencheckers.append(c) # type: ignore[arg-type] # pragma: no cover - warnings.warn( # pragma: no cover - "Checkers should subclass BaseTokenChecker " - "instead of using the __implements__ mechanism. Use of __implements__ " - "will no longer be supported in pylint 3.0", - DeprecationWarning, - ) rawcheckers = [ c for c in _checkers if isinstance(c, checkers.BaseRawFileChecker) ] - # TODO: 3.0: Remove deprecated if-statement - for c in _checkers: - with warnings.catch_warnings(): - warnings.filterwarnings("ignore", category=DeprecationWarning) - if ( - interfaces.implements(c, interfaces.IRawChecker) - and c not in rawcheckers - ): - rawcheckers.append(c) # type: ignore[arg-type] # pragma: no cover - warnings.warn( # pragma: no cover - "Checkers should subclass BaseRawFileChecker " - "instead of using the __implements__ mechanism. Use of __implements__ " - "will no longer be supported in pylint 3.0", - DeprecationWarning, - ) - # notify global begin for checker in _checkers: checker.open() walker.add_checker(checker) diff --git a/pylint/pyreverse/diagrams.py b/pylint/pyreverse/diagrams.py index 4437d3c4e..54b138752 100644 --- a/pylint/pyreverse/diagrams.py +++ b/pylint/pyreverse/diagrams.py @@ -207,13 +207,6 @@ class ClassDiagram(Figure, FilterMixIn): self.add_relationship(obj, par_obj, "specialization") except KeyError: continue - # implements link - for impl_node in node.implements: - try: - impl_obj = self.object_from_node(impl_node) - self.add_relationship(obj, impl_obj, "implements") - except KeyError: - continue # associations & aggregations links for name, values in list(node.aggregations_type.items()): diff --git a/pylint/pyreverse/inspector.py b/pylint/pyreverse/inspector.py index 523ff8171..aa52845b4 100644 --- a/pylint/pyreverse/inspector.py +++ b/pylint/pyreverse/inspector.py @@ -12,13 +12,11 @@ from __future__ import annotations import collections import os import traceback -import warnings from abc import ABC, abstractmethod -from collections.abc import Generator -from typing import Any, Callable, Optional +from typing import Callable, Optional import astroid -from astroid import nodes, util +from astroid import nodes from pylint import constants from pylint.pyreverse import utils @@ -39,27 +37,6 @@ def _astroid_wrapper( return None -def interfaces(node: nodes.ClassDef) -> Generator[Any, None, None]: - """Return an iterator on interfaces implemented by the given class node.""" - try: - implements = astroid.bases.Instance(node).getattr("__implements__")[0] - except astroid.exceptions.NotFoundError: - return - if implements.frame(future=True) is not node: - return - found = set() - missing = False - for iface in nodes.unpack_infer(implements): - if isinstance(iface, util.UninferableBase): - missing = True - continue - if iface not in found: - found.add(iface) - yield iface - if missing: - raise astroid.exceptions.InferenceError() - - class IdGeneratorMixIn: """Mixin adding the ability to generate integer uid.""" @@ -194,24 +171,6 @@ class Linker(IdGeneratorMixIn, utils.LocalsVisitor): if not isinstance(assignattr, nodes.Unknown): self.associations_handler.handle(assignattr, node) self.handle_assignattr_type(assignattr, node) - # resolve implemented interface - try: - ifaces = interfaces(node) - if ifaces is not None: - node.implements = list(ifaces) - if node.implements: - # TODO: 3.0: Remove support for __implements__ - warnings.warn( - "pyreverse will drop support for resolving and displaying " - "implemented interfaces in pylint 3.0. The implementation " - "relies on the '__implements__' attribute proposed in PEP 245" - ", which was rejected in 2006.", - DeprecationWarning, - ) - else: - node.implements = [] - except astroid.InferenceError: - node.implements = [] def visit_functiondef(self, node: nodes.FunctionDef) -> None: """Visit an astroid.Function node. diff --git a/pylint/reporters/base_reporter.py b/pylint/reporters/base_reporter.py index 3df970d80..5d4240723 100644 --- a/pylint/reporters/base_reporter.py +++ b/pylint/reporters/base_reporter.py @@ -6,7 +6,6 @@ from __future__ import annotations import os import sys -import warnings from typing import TYPE_CHECKING, TextIO from warnings import warn @@ -31,13 +30,6 @@ class BaseReporter: """Name of the reporter.""" def __init__(self, output: TextIO | None = None) -> None: - if getattr(self, "__implements__", None): - warnings.warn( - "Using the __implements__ inheritance pattern for BaseReporter is no " - "longer supported. Child classes should only inherit BaseReporter", - DeprecationWarning, - stacklevel=2, - ) self.linter: PyLinter self.section = 0 self.out: TextIO = output or sys.stdout |