Skip to content

Commit 6b25ff0

Browse files
committed
Subclass BaseRawFileChecker and BaseTokenChecker
1 parent e8aab74 commit 6b25ff0

13 files changed

+34
-63
lines changed

examples/custom_raw.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,17 @@
22

33
from astroid import nodes
44

5-
from pylint.checkers import BaseChecker
6-
from pylint.interfaces import IRawChecker
5+
from pylint.checkers import BaseRawFileChecker
76

87
if TYPE_CHECKING:
98
from pylint.lint import PyLinter
109

1110

12-
class MyRawChecker(BaseChecker):
11+
class MyRawChecker(BaseRawFileChecker):
1312
"""Check for line continuations with '\' instead of using triple
1413
quoted string or parenthesis
1514
"""
1615

17-
__implements__ = IRawChecker
18-
1916
name = "custom_raw"
2017
msgs = {
2118
"W9901": (

pylint/checkers/format.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
1919

2020
from astroid import nodes
2121

22-
from pylint.checkers import BaseTokenChecker
22+
from pylint.checkers import BaseRawFileChecker, BaseTokenChecker
2323
from pylint.checkers.utils import (
2424
check_messages,
2525
is_overload_stub,
2626
is_protocol_class,
2727
node_frame_class,
2828
)
2929
from pylint.constants import WarningScope
30-
from pylint.interfaces import IAstroidChecker, IRawChecker, ITokenChecker
30+
from pylint.interfaces import IAstroidChecker
3131
from pylint.utils.pragma_parser import OPTION_PO, PragmaParserError, parse_pragma
3232

3333
if TYPE_CHECKING:
@@ -195,7 +195,7 @@ def line(self, idx):
195195
return self._tokens[idx][4]
196196

197197

198-
class FormatChecker(BaseTokenChecker):
198+
class FormatChecker(BaseTokenChecker, BaseRawFileChecker):
199199
"""Formatting checker.
200200
201201
Checks for :
@@ -204,7 +204,7 @@ class FormatChecker(BaseTokenChecker):
204204
* line length
205205
"""
206206

207-
__implements__ = (ITokenChecker, IAstroidChecker, IRawChecker)
207+
__implements__ = IAstroidChecker
208208

209209
# configuration section name
210210
name = "format"
@@ -319,7 +319,7 @@ def new_line(self, tokens, line_end, line_start):
319319
self._lines[line_num] = line.split("\n")[0]
320320
self.check_lines(line, line_num)
321321

322-
def process_module(self, _node: nodes.Module) -> None:
322+
def process_module(self, node: nodes.Module) -> None:
323323
pass
324324

325325
# pylint: disable-next=too-many-return-statements

pylint/checkers/misc.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,18 @@
1212

1313
from astroid import nodes
1414

15-
from pylint.checkers import BaseChecker
16-
from pylint.interfaces import IRawChecker, ITokenChecker
15+
from pylint.checkers import BaseRawFileChecker, BaseTokenChecker
1716
from pylint.typing import ManagedMessage
1817
from pylint.utils.pragma_parser import OPTION_PO, PragmaParserError, parse_pragma
1918

2019
if TYPE_CHECKING:
2120
from pylint.lint import PyLinter
2221

2322

24-
class ByIdManagedMessagesChecker(BaseChecker):
23+
class ByIdManagedMessagesChecker(BaseRawFileChecker):
2524

2625
"""Checks for messages that are enabled or disabled by id instead of symbol."""
2726

28-
__implements__ = IRawChecker
2927
name = "miscellaneous"
3028
msgs = {
3129
"I0023": (
@@ -53,7 +51,7 @@ def process_module(self, node: nodes.Module) -> None:
5351
self._clear_by_id_managed_msgs()
5452

5553

56-
class EncodingChecker(BaseChecker):
54+
class EncodingChecker(BaseTokenChecker, BaseRawFileChecker):
5755

5856
"""BaseChecker for encoding issues.
5957
@@ -62,8 +60,6 @@ class EncodingChecker(BaseChecker):
6260
* encoding issues.
6361
"""
6462

65-
__implements__ = (IRawChecker, ITokenChecker)
66-
6763
# configuration section name
6864
name = "miscellaneous"
6965
msgs = {

pylint/checkers/raw_metrics.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from typing import TYPE_CHECKING, Any, cast
1010

1111
from pylint.checkers import BaseTokenChecker
12-
from pylint.interfaces import ITokenChecker
1312
from pylint.reporters.ureports.nodes import Table
1413
from pylint.utils import LinterStats, diff_string
1514

@@ -58,8 +57,6 @@ class RawMetricsChecker(BaseTokenChecker):
5857
* total number of empty lines
5958
"""
6059

61-
__implements__ = (ITokenChecker,)
62-
6360
# configuration section name
6461
name = "metrics"
6562
# configuration options

pylint/checkers/refactoring/refactoring_checker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ class RefactoringChecker(checkers.BaseTokenChecker):
196196
is a true "else if" node, or an "elif" node.
197197
"""
198198

199-
__implements__ = (interfaces.ITokenChecker, interfaces.IAstroidChecker)
199+
__implements__ = interfaces.IAstroidChecker
200200

201201
name = "refactoring"
202202

pylint/checkers/similar.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@
4747
import astroid
4848
from astroid import nodes
4949

50-
from pylint.checkers import BaseChecker, table_lines_from_stats
51-
from pylint.interfaces import IRawChecker
50+
from pylint.checkers import BaseChecker, BaseRawFileChecker, table_lines_from_stats
5251
from pylint.reporters.ureports.nodes import Table
5352
from pylint.typing import Options
5453
from pylint.utils import LinterStats, decoding_stream
@@ -736,14 +735,13 @@ def report_similarities(
736735

737736

738737
# wrapper to get a pylint checker from the similar class
739-
class SimilarChecker(BaseChecker, Similar):
738+
class SimilarChecker(BaseRawFileChecker, Similar):
740739
"""Checks for similarities and duplicated code.
741740
742741
This computation may be memory / CPU intensive, so you
743742
should disable it if you experiment some problems.
744743
"""
745744

746-
__implements__ = (IRawChecker,)
747745
# configuration section name
748746
name = "similarities"
749747
# messages
@@ -801,7 +799,7 @@ class SimilarChecker(BaseChecker, Similar):
801799
reports = (("RP0801", "Duplication", report_similarities),)
802800

803801
def __init__(self, linter: PyLinter) -> None:
804-
BaseChecker.__init__(self, linter)
802+
BaseRawFileChecker.__init__(self, linter)
805803
Similar.__init__(
806804
self,
807805
min_lines=self.linter.config.min_similarity_lines,

pylint/checkers/spelling.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
from pylint.checkers import BaseTokenChecker
1818
from pylint.checkers.utils import check_messages
19-
from pylint.interfaces import IAstroidChecker, ITokenChecker
19+
from pylint.interfaces import IAstroidChecker
2020

2121
if TYPE_CHECKING:
2222
from pylint.lint import PyLinter
@@ -183,7 +183,7 @@ def replace_code_but_leave_surrounding_characters(match_obj) -> str:
183183
class SpellingChecker(BaseTokenChecker):
184184
"""Check spelling in comments and docstrings."""
185185

186-
__implements__ = (ITokenChecker, IAstroidChecker)
186+
__implements__ = IAstroidChecker
187187
name = "spelling"
188188
msgs = {
189189
"C0401": (

pylint/checkers/unicode.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525

2626
from astroid import nodes
2727

28-
import pylint.checkers
2928
import pylint.interfaces
3029
import pylint.lint
30+
from pylint import checkers
3131

3232
_StrLike = TypeVar("_StrLike", str, bytes)
3333

@@ -298,7 +298,7 @@ def extract_codec_from_bom(first_line: bytes) -> str:
298298
raise ValueError("No BOM found. Could not detect Unicode codec.")
299299

300300

301-
class UnicodeChecker(pylint.checkers.BaseChecker):
301+
class UnicodeChecker(checkers.BaseRawFileChecker):
302302
"""Check characters that could be used to hide bad code to humans.
303303
304304
This includes:
@@ -318,8 +318,6 @@ class UnicodeChecker(pylint.checkers.BaseChecker):
318318
for background.
319319
"""
320320

321-
__implements__ = pylint.interfaces.IRawChecker
322-
323321
name = "unicode_checker"
324322

325323
msgs = {

pylint/extensions/check_elif.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from pylint.checkers import BaseTokenChecker
1313
from pylint.checkers.utils import check_messages
14-
from pylint.interfaces import HIGH, IAstroidChecker, ITokenChecker
14+
from pylint.interfaces import HIGH, IAstroidChecker
1515

1616
if TYPE_CHECKING:
1717
from pylint.lint import PyLinter
@@ -20,7 +20,7 @@
2020
class ElseifUsedChecker(BaseTokenChecker):
2121
"""Checks for use of "else if" when an "elif" could be used."""
2222

23-
__implements__ = (ITokenChecker, IAstroidChecker)
23+
__implements__ = IAstroidChecker
2424
name = "else_if_used"
2525
msgs = {
2626
"R5501": (

pylint/extensions/empty_comment.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88

99
from astroid import nodes
1010

11-
from pylint.checkers import BaseChecker
12-
from pylint.interfaces import IRawChecker
11+
from pylint.checkers import BaseRawFileChecker
1312

1413
if TYPE_CHECKING:
1514
from pylint.lint import PyLinter
@@ -40,8 +39,7 @@ def comment_part_of_string(line, comment_idx):
4039
return False
4140

4241

43-
class CommentChecker(BaseChecker):
44-
__implements__ = IRawChecker
42+
class CommentChecker(BaseRawFileChecker):
4543

4644
name = "refactoring"
4745
msgs = {

pylint/lint/pylinter.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,6 @@ class PyLinter(
209209
is reporter member; see check_parallel function for more details.
210210
"""
211211

212-
__implements__ = (interfaces.ITokenChecker,)
213-
214212
name = MAIN_CHECKER_NAME
215213
msgs = MSGS
216214
# Will be used like this : datetime.now().strftime(crash_file_path)

tests/benchmark/test_baseline_benchmarks.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
import pytest
1515
from astroid import nodes
1616

17-
import pylint.interfaces
18-
from pylint.checkers.base_checker import BaseChecker
17+
from pylint.checkers import BaseRawFileChecker
1918
from pylint.lint import PyLinter, Run, check_parallel
2019
from pylint.testutils import GenericTestReporter as Reporter
2120
from pylint.typing import FileItem
@@ -30,15 +29,13 @@ def _empty_filepath():
3029
)
3130

3231

33-
class SleepingChecker(BaseChecker):
32+
class SleepingChecker(BaseRawFileChecker):
3433
"""A checker that sleeps, the wall-clock time should reduce as we add workers.
3534
3635
As we apply a roughly constant amount of "work" in this checker any variance is
3736
likely to be caused by the pylint system.
3837
"""
3938

40-
__implements__ = (pylint.interfaces.IRawChecker,)
41-
4239
name = "sleeper"
4340
msgs = {
4441
"R9999": (
@@ -49,23 +46,21 @@ class SleepingChecker(BaseChecker):
4946
}
5047
sleep_duration = 0.5 # the time to pretend we're doing work for
5148

52-
def process_module(self, _node: nodes.Module) -> None:
49+
def process_module(self, node: nodes.Module) -> None:
5350
"""Sleeps for `sleep_duration` on each call.
5451
5552
This effectively means each file costs ~`sleep_duration`+framework overhead
5653
"""
5754
time.sleep(self.sleep_duration)
5855

5956

60-
class SleepingCheckerLong(BaseChecker):
57+
class SleepingCheckerLong(BaseRawFileChecker):
6158
"""A checker that sleeps, the wall-clock time should reduce as we add workers.
6259
6360
As we apply a roughly constant amount of "work" in this checker any variance is
6461
likely to be caused by the pylint system.
6562
"""
6663

67-
__implements__ = (pylint.interfaces.IRawChecker,)
68-
6964
name = "long-sleeper"
7065
msgs = {
7166
"R9999": (
@@ -76,19 +71,17 @@ class SleepingCheckerLong(BaseChecker):
7671
}
7772
sleep_duration = 0.5 # the time to pretend we're doing work for
7873

79-
def process_module(self, _node: nodes.Module) -> None:
74+
def process_module(self, node: nodes.Module) -> None:
8075
"""Sleeps for `sleep_duration` on each call.
8176
8277
This effectively means each file costs ~`sleep_duration`+framework overhead
8378
"""
8479
time.sleep(self.sleep_duration)
8580

8681

87-
class NoWorkChecker(BaseChecker):
82+
class NoWorkChecker(BaseRawFileChecker):
8883
"""A checker that sleeps, the wall-clock time should change as we add threads."""
8984

90-
__implements__ = (pylint.interfaces.IRawChecker,)
91-
9285
name = "sleeper"
9386
msgs = {
9487
"R9999": (
@@ -98,7 +91,7 @@ class NoWorkChecker(BaseChecker):
9891
)
9992
}
10093

101-
def process_module(self, _node: nodes.Module) -> None:
94+
def process_module(self, node: nodes.Module) -> None:
10295
pass
10396

10497

0 commit comments

Comments
 (0)