diff options
author | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2021-12-27 21:30:34 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-27 21:30:34 +0100 |
commit | 7d2584251552283bf95893019e74dad0390dc65c (patch) | |
tree | 7b5b8fa573a94d73b97741789a3e1fe35c7e7824 /examples | |
parent | 691b41b3ddd3b533bce4d6a1f03ebc1e5cacf508 (diff) | |
download | pylint-git-7d2584251552283bf95893019e74dad0390dc65c.tar.gz |
Add typing and uniformize the checker registering in Pylinter (#5558)
Remove verbose docstring in code, keep them in example and doc
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/custom.py | 12 | ||||
-rw-r--r-- | examples/custom_raw.py | 12 | ||||
-rw-r--r-- | examples/deprecation_checker.py | 12 |
3 files changed, 23 insertions, 13 deletions
diff --git a/examples/custom.py b/examples/custom.py index c7429f629..695f77d20 100644 --- a/examples/custom.py +++ b/examples/custom.py @@ -1,11 +1,16 @@ +from typing import TYPE_CHECKING + from astroid import nodes from pylint.checkers import BaseChecker from pylint.interfaces import IAstroidChecker +if TYPE_CHECKING: + from pylint.lint import PyLinter -# This is our checker class. # Checkers should always inherit from `BaseChecker`. + + class MyAstroidChecker(BaseChecker): """Add class member attributes to the class local's dictionary.""" @@ -60,10 +65,9 @@ class MyAstroidChecker(BaseChecker): in_class.locals[param.name] = node -def register(linter): - """This required method auto registers the checker. +def register(linter: "PyLinter") -> None: + """This required method auto registers the checker during initialization. :param linter: The linter to register the checker to. - :type linter: pylint.lint.PyLinter """ linter.register_checker(MyAstroidChecker(linter)) diff --git a/examples/custom_raw.py b/examples/custom_raw.py index 5f747869f..045f22ff4 100644 --- a/examples/custom_raw.py +++ b/examples/custom_raw.py @@ -1,8 +1,13 @@ +from typing import TYPE_CHECKING + from astroid import nodes from pylint.checkers import BaseChecker from pylint.interfaces import IRawChecker +if TYPE_CHECKING: + from pylint.lint import PyLinter + class MyRawChecker(BaseChecker): """check for line continuations with '\' instead of using triple @@ -35,6 +40,9 @@ class MyRawChecker(BaseChecker): self.add_message("backslash-line-continuation", line=lineno) -def register(linter): - """required method to auto register this checker""" +def register(linter: "PyLinter") -> None: + """This required method auto registers the checker during initialization. + + :param linter: The linter to register the checker to. + """ linter.register_checker(MyRawChecker(linter)) diff --git a/examples/deprecation_checker.py b/examples/deprecation_checker.py index 93910b724..d3dca4e07 100644 --- a/examples/deprecation_checker.py +++ b/examples/deprecation_checker.py @@ -38,11 +38,14 @@ from module mymodule: ------------------------------------------------------------------ Your code has been rated at 2.00/10 (previous run: 2.00/10, +0.00) """ -from typing import Set, Tuple, Union +from typing import TYPE_CHECKING, Set, Tuple, Union from pylint.checkers import BaseChecker, DeprecatedMixin from pylint.interfaces import IAstroidChecker +if TYPE_CHECKING: + from pylint.lint import PyLinter + class DeprecationChecker(DeprecatedMixin, BaseChecker): """Class implementing deprecation checker.""" @@ -90,10 +93,5 @@ class DeprecationChecker(DeprecatedMixin, BaseChecker): return () -def register(linter): - """This required method auto registers the checker. - - :param linter: The linter to register the checker to. - :type linter: pylint.lint.PyLinter - """ +def register(linter: "PyLinter") -> None: linter.register_checker(DeprecationChecker(linter)) |