Skip to content

Commit

Permalink
Add future option to OptionsProviderMixIn
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielNoord committed Dec 22, 2021
1 parent 95db076 commit a329ede
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
12 changes: 10 additions & 2 deletions pylint/checkers/base_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
import functools
import sys
from inspect import cleandoc
from typing import Any, Optional

Expand All @@ -30,6 +31,11 @@
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):
Expand All @@ -47,14 +53,16 @@ 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."""
if self.name is not None:
self.name = self.name.lower()
super().__init__()
self.linter = linter
super().__init__(future=future_option_parsing)

def __gt__(self, other):
"""Permit to sort a list of Checker by name."""
Expand Down
13 changes: 12 additions & 1 deletion pylint/config/options_provider_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@


import optparse # pylint: disable=deprecated-module
import sys
from typing import Any, Dict, Tuple

from pylint.config import utils
from pylint.config.option import _validate

if sys.version_info >= (3, 8):
from typing import Literal
else:
from typing_extensions import Literal


class UnsupportedAction(Exception):
"""raised by set_option when it doesn't know what to do for an action"""
Expand All @@ -21,7 +28,11 @@ class OptionsProviderMixIn:
options: Tuple[Tuple[str, Dict[str, Any]], ...] = ()
level = 0

def __init__(self):
def __init__(self, *, future: Literal[None, True] = None):
if future:
for opt, optdict in self.options:
argument = utils._convert_option_to_argument(opt, optdict)
self.linter.namespace_test[opt] = argument # type: ignore[attr-defined] # Always mixed in with a checker
self.config = optparse.Values()
self.load_defaults()

Expand Down
3 changes: 3 additions & 0 deletions pylint/lint/pylinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,9 @@ def __init__(
):
"""Some stuff has to be done before ancestors initialization...
messages store / checkers / reporter / astroid manager"""
self.namespace_test: Dict[str, config._Argument] = {}
"""Temporary dictionary for testing purposes"""

# Attributes for reporters
self.reporter: Union[reporters.BaseReporter, reporters.MultiReporter]
if reporter:
Expand Down
2 changes: 1 addition & 1 deletion tests/lint/unittest_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ class FakeConfig:
assert MSG_STATE_SCOPE_MODULE == linter._get_message_state_scope("W0101", 3)
linter.enable("W0102", scope="module", line=3)
assert MSG_STATE_SCOPE_MODULE == linter._get_message_state_scope("W0102", 3)
linter.config = FakeConfig()
linter.config = FakeConfig() # type: ignore[assignment] # This should be optparse.Values()
assert MSG_STATE_CONFIDENCE == linter._get_message_state_scope(
"this-is-bad", confidence=interfaces.INFERENCE
)
Expand Down

0 comments on commit a329ede

Please sign in to comment.