From 04937c3098f2497f88792085f15c36741b9a1f15 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Sun, 7 Mar 2021 16:49:57 +0100 Subject: Typing changes + disable unused pylint plugin for pre-commit (#4205) --- .pre-commit-config.yaml | 3 ++- examples/deprecation_checker.py | 8 +++++--- pylint/checkers/deprecated.py | 11 ++++++----- tox.ini | 1 + 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c46caf4b3..f2d3b71ea 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -49,8 +49,9 @@ repos: entry: pylint language: system types: [python] + args: ["-rn", "-sn", "--rcfile=pylintrc", "--load-plugins=pylint.extensions.docparams"] + # disabled plugins: pylint.extensions.mccabe exclude: tests/functional/|tests/input|tests/extensions/data|tests/regrtest_data/|tests/data/|doc/ - args: [--load-plugins=pylint.extensions.docparams, pylint.extensions.mccabe, -rn] - id: fix-documentation name: Fix documentation entry: python3 -m script.fix_documentation diff --git a/examples/deprecation_checker.py b/examples/deprecation_checker.py index fba6a54de..93910b724 100644 --- a/examples/deprecation_checker.py +++ b/examples/deprecation_checker.py @@ -38,7 +38,7 @@ from module mymodule: ------------------------------------------------------------------ Your code has been rated at 2.00/10 (previous run: 2.00/10, +0.00) """ -from typing import Set, Tuple +from typing import Set, Tuple, Union from pylint.checkers import BaseChecker, DeprecatedMixin from pylint.interfaces import IAstroidChecker @@ -56,7 +56,7 @@ class DeprecationChecker(DeprecatedMixin, BaseChecker): # The name defines a custom section of the config for this checker. name = "deprecated" - def deprecated_methods(self) -> Set: + def deprecated_methods(self) -> Set[str]: """Callback method called by DeprecatedMixin for every method/function found in the code. Returns: @@ -64,7 +64,9 @@ class DeprecationChecker(DeprecatedMixin, BaseChecker): """ return {"mymodule.deprecated_function", "mymodule.MyClass.deprecated_method"} - def deprecated_arguments(self, method: str) -> Tuple: + def deprecated_arguments( + self, method: str + ) -> Tuple[Tuple[Union[int, None], str], ...]: """Callback returning the deprecated arguments of method/function. Returns: diff --git a/pylint/checkers/deprecated.py b/pylint/checkers/deprecated.py index 8fe491c15..ff7c2a606 100644 --- a/pylint/checkers/deprecated.py +++ b/pylint/checkers/deprecated.py @@ -2,9 +2,8 @@ # For details: https://github.com/PyCQA/pylint/blob/master/COPYING """Checker mixin for deprecated functionality.""" -from collections.abc import Iterable from itertools import chain -from typing import Any +from typing import Any, Container, Iterable, Tuple, Union import astroid @@ -39,7 +38,7 @@ class DeprecatedMixin: "deprecated-method", "deprecated-argument", ) - def visit_call(self, node: astroid.node_classes.Call) -> None: + def visit_call(self, node: astroid.Call) -> None: """Called when a :class:`.astroid.node_classes.Call` node is visited.""" try: for inferred in node.func.infer(): @@ -48,7 +47,7 @@ class DeprecatedMixin: except astroid.InferenceError: pass - def deprecated_methods(self) -> Iterable: + def deprecated_methods(self) -> Container[str]: """Callback returning the deprecated methods/functions. Returns: @@ -57,7 +56,9 @@ class DeprecatedMixin: # pylint: disable=no-self-use return () - def deprecated_arguments(self, method: str) -> Iterable: + def deprecated_arguments( + self, method: str + ) -> Iterable[Tuple[Union[int, None], str]]: """Callback returning the deprecated arguments of method/function. Args: diff --git a/tox.ini b/tox.ini index 85a0160f3..52cead59c 100644 --- a/tox.ini +++ b/tox.ini @@ -11,6 +11,7 @@ deps = commands = pre-commit run pylint --all-files + [testenv:formatting] basepython = python3 deps = -- cgit v1.2.1