From 9e49b6a89468c0b6fc959be936f9d8b773b41b87 Mon Sep 17 00:00:00 2001 From: Pavol Juhas Date: Thu, 3 Oct 2024 17:49:14 -0700 Subject: [PATCH] Adjust pylint_copyright_checker for the pylint-3 API Follow the `examples/custom_raw.py` in the pylint repository. Fixes #6351 --- dev_tools/pylint_copyright_checker.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/dev_tools/pylint_copyright_checker.py b/dev_tools/pylint_copyright_checker.py index 6b216a40116..0a5c69e25dc 100644 --- a/dev_tools/pylint_copyright_checker.py +++ b/dev_tools/pylint_copyright_checker.py @@ -12,24 +12,24 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations + +from typing import TYPE_CHECKING + from astroid import nodes +from pylint.checkers import BaseRawFileChecker -from pylint.checkers import BaseChecker -from pylint.interfaces import IRawChecker +if TYPE_CHECKING: + from pylint.lint import PyLinter -class CopyrightChecker(BaseChecker): - r"""Check for the copyright notices at the beginning of a Python source file. +class CopyrightChecker(BaseRawFileChecker): + """Check for the copyright notices at the beginning of a Python source file. This checker can be disabled by putting `# pylint: disable=wrong-or-nonexistent-copyright-notice` at the beginning of a file. """ - __implements__ = IRawChecker - - # The priority must be negtive. Pylint runs plugins with smaller priorities first. - priority = -1 - name = "copyright-notice" msgs = { "R0001": ( @@ -41,7 +41,7 @@ class CopyrightChecker(BaseChecker): options = () def process_module(self, node: nodes.Module) -> None: - r"""Check whether the copyright notice is correctly placed in the source file of a module. + """Check whether the copyright notice is correctly placed in the source file of a module. Compare the first lines of a source file against the standard copyright notice (i.e., the `golden` variable below). Suffix whitespace (including newline symbols) is not considered @@ -109,8 +109,8 @@ def skip_shebang(stream): return -def register(linter): - r"""Register this checker to pylint. +def register(linter: PyLinter): + """Register this checker to pylint. The registration is done automatically if this file is in $PYTHONPATH. """