summaryrefslogtreecommitdiff
path: root/pylint/checkers/base_checker.py
diff options
context:
space:
mode:
authorDaniƫl van Noord <13665637+DanielNoord@users.noreply.github.com>2022-03-29 14:44:27 +0200
committerGitHub <noreply@github.com>2022-03-29 14:44:27 +0200
commit0bc45e9037416203bd11f83b84a906fcec1a47f0 (patch)
treeaed06a43f53926fdb2b4045b381e31df9f2247ac /pylint/checkers/base_checker.py
parent700752a03604e4fe1b73e5f4200649c157e6eaaa (diff)
downloadpylint-git-0bc45e9037416203bd11f83b84a906fcec1a47f0.tar.gz
Create an `Argument` class and allow convertion of optdict into them (#5584)
* Use config initialization of ``_ArgumentsManager`` * Allow ``BaseChecker`` to register on a ``_ArgumentsManager`` * Use the ``argparse`` config handler in ``logging.py`` and add tests
Diffstat (limited to 'pylint/checkers/base_checker.py')
-rw-r--r--pylint/checkers/base_checker.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/pylint/checkers/base_checker.py b/pylint/checkers/base_checker.py
index 1cdc014fc..21c63364a 100644
--- a/pylint/checkers/base_checker.py
+++ b/pylint/checkers/base_checker.py
@@ -3,18 +3,25 @@
# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt
import functools
+import sys
from inspect import cleandoc
from typing import Any, Optional
from astroid import nodes
from pylint.config import OptionsProviderMixIn
+from pylint.config.exceptions import MissingArgumentManager
from pylint.constants import _MSG_ORDER, WarningScope
from pylint.exceptions import InvalidMessageError
from pylint.interfaces import Confidence, IRawChecker, ITokenChecker, implements
from pylint.message.message_definition import MessageDefinition
from pylint.utils import get_rst_section, get_rst_title
+if sys.version_info >= (3, 8):
+ from typing import Literal
+else:
+ from typing_extensions import Literal
+
@functools.total_ordering
class BaseChecker(OptionsProviderMixIn):
@@ -32,16 +39,26 @@ class BaseChecker(OptionsProviderMixIn):
# mark this checker as enabled or not.
enabled: bool = True
- def __init__(self, linter=None):
+ def __init__(
+ self, linter=None, *, future_option_parsing: Literal[None, True] = None
+ ):
"""Checker instances should have the linter as argument.
:param ILinter linter: is an object implementing ILinter.
+ :raises MissingArgumentManager: If no linter object is passed.
"""
if self.name is not None:
self.name = self.name.lower()
super().__init__()
self.linter = linter
+ if future_option_parsing:
+ # We need a PyLinter object that subclasses _ArgumentsManager to register options
+ if not self.linter:
+ raise MissingArgumentManager
+
+ self.linter._register_options_provider(self)
+
def __gt__(self, other):
"""Permit to sort a list of Checker by name."""
return f"{self.name}{self.msgs}".__gt__(f"{other.name}{other.msgs}")