diff options
author | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2021-12-22 18:04:36 +0100 |
---|---|---|
committer | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2021-12-24 09:39:46 +0100 |
commit | c536511657a51fd1c31f668b7277d0e4e5a6586e (patch) | |
tree | 0dfc641330385fce9bd31edf849123b1eaa7b091 | |
parent | 7a0a8d8ed54d485f60dfc0c827a7ed980d5fc405 (diff) | |
download | pylint-git-c536511657a51fd1c31f668b7277d0e4e5a6586e.tar.gz |
Add proper import in doc examples
-rw-r--r-- | doc/how_tos/custom_checkers.rst | 8 | ||||
-rw-r--r-- | doc/how_tos/plugins.rst | 16 | ||||
-rw-r--r-- | doc/how_tos/transform_plugins.rst | 6 | ||||
-rw-r--r-- | pylint/checkers/ellipsis_checker.py | 8 |
4 files changed, 36 insertions, 2 deletions
diff --git a/doc/how_tos/custom_checkers.rst b/doc/how_tos/custom_checkers.rst index 36fcc07a3..30c70d63a 100644 --- a/doc/how_tos/custom_checkers.rst +++ b/doc/how_tos/custom_checkers.rst @@ -201,6 +201,14 @@ Add the ``register`` function to the top level of the file. .. code-block:: python + from typing import TYPE_CHECKING + + import astroid + + if TYPE_CHECKING: + from pylint.lint import PyLinter + + def register(linter: "PyLinter") -> None: """This required method auto registers the checker during initialization. diff --git a/doc/how_tos/plugins.rst b/doc/how_tos/plugins.rst index 5fa094c29..bc2c0f14c 100644 --- a/doc/how_tos/plugins.rst +++ b/doc/how_tos/plugins.rst @@ -25,6 +25,14 @@ So a basic hello-world plugin can be implemented as: .. sourcecode:: python # Inside hello_plugin.py + from typing import TYPE_CHECKING + + import astroid + + if TYPE_CHECKING: + from pylint.lint import PyLinter + + def register(linter: "PyLinter") -> None: """This required method auto registers the checker during initialization. @@ -47,6 +55,14 @@ We can extend hello-world plugin to ignore some specific names using .. sourcecode:: python # Inside hello_plugin.py + from typing import TYPE_CHECKING + + import astroid + + if TYPE_CHECKING: + from pylint.lint import PyLinter + + def register(linter: "PyLinter") -> None: """This required method auto registers the checker during initialization. diff --git a/doc/how_tos/transform_plugins.rst b/doc/how_tos/transform_plugins.rst index 4980051a6..031faa0f1 100644 --- a/doc/how_tos/transform_plugins.rst +++ b/doc/how_tos/transform_plugins.rst @@ -66,8 +66,14 @@ Module, Class, Function etc. In our case we need to transform a class. It can be .. sourcecode:: python + from typing import TYPE_CHECKING + import astroid + if TYPE_CHECKING: + from pylint.lint import PyLinter + + def register(linter: "PyLinter") -> None: """This required method auto registers the checker during initialization. diff --git a/pylint/checkers/ellipsis_checker.py b/pylint/checkers/ellipsis_checker.py index 6ef9299a3..ab1c14be4 100644 --- a/pylint/checkers/ellipsis_checker.py +++ b/pylint/checkers/ellipsis_checker.py @@ -1,11 +1,15 @@ """Ellipsis checker for Python code """ +from typing import TYPE_CHECKING + from astroid import nodes from pylint.checkers import BaseChecker from pylint.checkers.utils import check_messages from pylint.interfaces import IAstroidChecker -from pylint.lint import PyLinter + +if TYPE_CHECKING: + from pylint.lint import PyLinter class EllipsisChecker(BaseChecker): @@ -45,7 +49,7 @@ class EllipsisChecker(BaseChecker): self.add_message("unnecessary-ellipsis", node=node) -def register(linter: PyLinter) -> None: +def register(linter: "PyLinter") -> None: """This required method auto registers the checker during initialization. :param linter: The linter to register the checker to. |