1111from itertools import chain
1212
1313from pylint .lint import Run
14+ from pylint .message import Message
1415from pylint .reporters import JSONReporter
1516from pylint .testutils ._primer .package_to_lint import PackageToLint
1617from pylint .testutils ._primer .primer_command import PackageMessages , PrimerCommand
@@ -24,20 +25,18 @@ def run(self) -> None:
2425 packages : PackageMessages = {}
2526
2627 for package , data in self .packages .items ():
27- output = self ._lint_package (data )
28- packages [package ] = output
28+ packages [package ] = self ._lint_package (data )
2929 print (f"Successfully primed { package } ." )
3030
3131 astroid_errors = []
3232 other_fatal_msgs = []
3333 for msg in chain .from_iterable (packages .values ()):
34- if msg ["type" ] == "fatal" :
35- # Remove the crash template location if we're running on GitHub.
36- # 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" :
34+ if msg .category == "fatal" :
35+ if GITHUB_CRASH_TEMPLATE_LOCATION in msg .msg :
36+ # Remove the crash template location if we're running on GitHub.
37+ # We were falsely getting "new" errors when the timestamp changed.
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 )
@@ -48,7 +47,13 @@ def run(self) -> None:
4847 "w" ,
4948 encoding = "utf-8" ,
5049 ) as f :
51- json .dump (packages , f )
50+ json .dump (
51+ {
52+ p : [JSONReporter .serialize (m ) for m in msgs ]
53+ for p , msgs in packages .items ()
54+ },
55+ f ,
56+ )
5257
5358 # Fail loudly (and fail CI pipelines) if any fatal errors are found,
5459 # unless they are astroid-errors, in which case just warn.
@@ -59,7 +64,7 @@ def run(self) -> None:
5964 warnings .warn (f"Fatal errors traced to astroid: { astroid_errors } " )
6065 assert not other_fatal_msgs , other_fatal_msgs
6166
62- def _lint_package (self , data : PackageToLint ) -> list [dict [ str , str | int ] ]:
67+ def _lint_package (self , data : PackageToLint ) -> list [Message ]:
6368 # We want to test all the code we can
6469 enables = ["--enable-all-extensions" , "--enable=all" ]
6570 # Duplicate code takes too long and is relatively safe
@@ -69,4 +74,4 @@ def _lint_package(self, data: PackageToLint) -> list[dict[str, str | int]]:
6974 output = StringIO ()
7075 reporter = JSONReporter (output )
7176 Run (arguments , reporter = reporter , exit = False )
72- return json .loads (output .getvalue ())
77+ return [ JSONReporter . deserialize ( m ) for m in json .loads (output .getvalue ())]
0 commit comments