From 34cce21d29f9692a34fec22a76bee70939e628a5 Mon Sep 17 00:00:00 2001 From: Matus Valo Date: Sat, 20 Feb 2021 22:01:03 +0100 Subject: Move message definition to the DeprecatedMixin class --- examples/deprecation_checker.py | 20 ++++++-------------- pylint/checkers/deprecated.py | 9 +++++++++ pylint/checkers/stdlib.py | 2 +- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/examples/deprecation_checker.py b/examples/deprecation_checker.py index a6a8e3963..7059c89ab 100644 --- a/examples/deprecation_checker.py +++ b/examples/deprecation_checker.py @@ -33,25 +33,17 @@ from pylint.checkers import BaseChecker, DeprecatedMixin, utils from pylint.interfaces import IAstroidChecker -class DeprecationChecker(BaseChecker, DeprecatedMixin): +class DeprecationChecker(DeprecatedMixin, BaseChecker): """Class implementing deprecation checker.""" + # DeprecationMixin class is Mixin class implementing logic for searching deprecated methods and functions. + # The list of deprecated methods/functions is defined by implemeting class via deprecated_methods callback. + # DeprecatedMixin class is overriding attrigutes of BaseChecker hence must be specified *before* BaseChecker + # in list of base classes. + __implements__ = (IAstroidChecker,) # The name defines a custom section of the config for this checker. name = "deprecated" - # This class variable declares the messages (ie the warnings and errors) - # that the checker can emit. - msgs = { - # Each message has a code, a message that the user will see, - # a unique symbol that identifies the message, - # and a detailed help message - # that will be included in the documentation. - "W1505": ( - "Using deprecated method %s()", - "deprecated-method", - "The method is marked as deprecated and will be removed in the future.", - ), - } @utils.check_messages( "deprecated-method", diff --git a/pylint/checkers/deprecated.py b/pylint/checkers/deprecated.py index 0bbad05ee..54254340d 100644 --- a/pylint/checkers/deprecated.py +++ b/pylint/checkers/deprecated.py @@ -4,6 +4,7 @@ """Checker mixin for deprecated functionality.""" import abc +from typing import Any import astroid @@ -19,6 +20,14 @@ class DeprecatedMixin(metaclass=abc.ABCMeta): A class imlementing mixin must define "deprecated-method" Message. """ + msgs: Any = { + "W1505": ( + "Using deprecated method %s()", + "deprecated-method", + "The method is marked as deprecated and will be removed in the future.", + ), + } + @abc.abstractmethod def deprecated_methods(self): """Callback returning the deprecated methods/functions. diff --git a/pylint/checkers/stdlib.py b/pylint/checkers/stdlib.py index ad6e4f855..26bce9435 100644 --- a/pylint/checkers/stdlib.py +++ b/pylint/checkers/stdlib.py @@ -80,7 +80,7 @@ def _check_mode_str(mode): return True -class StdlibChecker(BaseChecker, DeprecatedMixin): +class StdlibChecker(DeprecatedMixin, BaseChecker): __implements__ = (IAstroidChecker,) name = "stdlib" -- cgit v1.2.1