Skip to content

Commit e252f7d

Browse files
[primer] Refactor the primer to use 'pylint.message.Message'
1 parent 3a76bd6 commit e252f7d

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

pylint/testutils/_primer/primer_command.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
import abc
88
import argparse
99
from pathlib import Path
10-
from typing import Dict, List, Union
10+
from typing import Dict, List
1111

12+
from pylint.message import Message
1213
from pylint.testutils._primer import PackageToLint
1314

14-
PackageMessages = Dict[str, List[Dict[str, Union[str, int]]]]
15+
PackageMessages = Dict[str, List[Message]]
1516

1617

1718
class PrimerCommand:

pylint/testutils/_primer/primer_run_command.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from itertools import chain
1212

1313
from pylint.lint import Run
14+
from pylint.message import Message
1415
from pylint.reporters import JSONReporter
1516
from pylint.testutils._primer.package_to_lint import PackageToLint
1617
from pylint.testutils._primer.primer_command import PackageMessages, PrimerCommand
@@ -22,22 +23,20 @@
2223
class RunCommand(PrimerCommand):
2324
def run(self) -> None:
2425
packages: PackageMessages = {}
25-
2626
for package, data in self.packages.items():
27-
output = self._lint_package(data)
28-
packages[package] = output
27+
packages[package] = self._lint_package(data)
2928
print(f"Successfully primed {package}.")
3029

3130
astroid_errors = []
3231
other_fatal_msgs = []
3332
for msg in chain.from_iterable(packages.values()):
34-
if msg["type"] == "fatal":
33+
if msg.category == "fatal":
3534
# Remove the crash template location if we're running on GitHub.
3635
# We were falsely getting "new" errors when the timestamp changed.
37-
assert isinstance(msg["message"], str)
38-
if GITHUB_CRASH_TEMPLATE_LOCATION in msg["message"]:
39-
msg["message"] = msg["message"].rsplit(CRASH_TEMPLATE_INTRO)[0]
40-
if msg["symbol"] == "astroid-error":
36+
assert isinstance(msg.msg, str)
37+
if GITHUB_CRASH_TEMPLATE_LOCATION in msg.msg:
38+
msg.msg = msg.msg.rsplit(CRASH_TEMPLATE_INTRO)[0]
39+
if msg.symbol == "astroid-error":
4140
astroid_errors.append(msg)
4241
else:
4342
other_fatal_msgs.append(msg)
@@ -59,7 +58,7 @@ def run(self) -> None:
5958
warnings.warn(f"Fatal errors traced to astroid: {astroid_errors}")
6059
assert not other_fatal_msgs, other_fatal_msgs
6160

62-
def _lint_package(self, data: PackageToLint) -> list[dict[str, str | int]]:
61+
def _lint_package(self, data: PackageToLint) -> list[Message]:
6362
# We want to test all the code we can
6463
enables = ["--enable-all-extensions", "--enable=all"]
6564
# Duplicate code takes too long and is relatively safe
@@ -69,4 +68,4 @@ def _lint_package(self, data: PackageToLint) -> list[dict[str, str | int]]:
6968
output = StringIO()
7069
reporter = JSONReporter(output)
7170
Run(arguments, reporter=reporter, exit=False)
72-
return json.loads(output.getvalue())
71+
return [Message(*m) for m in json.loads(output.getvalue())]

0 commit comments

Comments
 (0)