2
2
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
3
3
# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt
4
4
5
+ from __future__ import annotations
6
+
5
7
import csv
6
8
import operator
7
9
import platform
10
12
from io import StringIO
11
13
from pathlib import Path
12
14
from typing import Counter as CounterType
13
- from typing import Dict , List , Optional , TextIO , Tuple , Union
15
+ from typing import TextIO , Tuple
14
16
15
17
import pytest
16
18
from _pytest .config import Config
@@ -37,15 +39,15 @@ class LintModuleTest:
37
39
maxDiff = None
38
40
39
41
def __init__ (
40
- self , test_file : FunctionalTestFile , config : Optional [ Config ] = None
42
+ self , test_file : FunctionalTestFile , config : Config | None = None
41
43
) -> None :
42
44
_test_reporter = FunctionalTestReporter ()
43
45
self ._linter = PyLinter ()
44
46
self ._linter .namespace .persistent = 0
45
47
checkers .initialize (self ._linter )
46
48
47
49
# See if test has its own .rc file, if so we use that one
48
- rc_file : Union [ Path , str ] = PYLINTRC
50
+ rc_file : Path | str = PYLINTRC
49
51
try :
50
52
rc_file = test_file .option_file
51
53
self ._linter .disable ("suppressed-message" )
@@ -140,7 +142,7 @@ def get_expected_messages(stream: TextIO) -> MessageCounter:
140
142
def multiset_difference (
141
143
expected_entries : MessageCounter ,
142
144
actual_entries : MessageCounter ,
143
- ) -> Tuple [MessageCounter , Dict [ Tuple [int , str ], int ]]:
145
+ ) -> tuple [MessageCounter , dict [ tuple [int , str ], int ]]:
144
146
"""Takes two multisets and compares them.
145
147
146
148
A multiset is a dict with the cardinality of the key as the value.
@@ -168,7 +170,7 @@ def _open_source_file(self) -> TextIO:
168
170
return open (self ._test_file .source , encoding = "latin1" )
169
171
return open (self ._test_file .source , encoding = "utf8" )
170
172
171
- def _get_expected (self ) -> Tuple [MessageCounter , List [OutputLine ]]:
173
+ def _get_expected (self ) -> tuple [MessageCounter , list [OutputLine ]]:
172
174
with self ._open_source_file () as f :
173
175
expected_msgs = self .get_expected_messages (f )
174
176
if not expected_msgs :
@@ -180,8 +182,8 @@ def _get_expected(self) -> Tuple[MessageCounter, List[OutputLine]]:
180
182
]
181
183
return expected_msgs , expected_output_lines
182
184
183
- def _get_actual (self ) -> Tuple [MessageCounter , List [OutputLine ]]:
184
- messages : List [Message ] = self ._linter .reporter .messages
185
+ def _get_actual (self ) -> tuple [MessageCounter , list [OutputLine ]]:
186
+ messages : list [Message ] = self ._linter .reporter .messages
185
187
messages .sort (key = lambda m : (m .line , m .symbol , m .msg ))
186
188
received_msgs : MessageCounter = Counter ()
187
189
received_output_lines = []
@@ -212,7 +214,7 @@ def error_msg_for_unequal_messages(
212
214
self ,
213
215
actual_messages : MessageCounter ,
214
216
expected_messages : MessageCounter ,
215
- actual_output : List [OutputLine ],
217
+ actual_output : list [OutputLine ],
216
218
) -> str :
217
219
msg = [f'Wrong results for file "{ self ._test_file .base } ":' ]
218
220
missing , unexpected = self .multiset_difference (
@@ -232,8 +234,8 @@ def error_msg_for_unequal_messages(
232
234
233
235
def error_msg_for_unequal_output (
234
236
self ,
235
- expected_lines : List [OutputLine ],
236
- received_lines : List [OutputLine ],
237
+ expected_lines : list [OutputLine ],
238
+ received_lines : list [OutputLine ],
237
239
) -> str :
238
240
missing = set (expected_lines ) - set (received_lines )
239
241
unexpected = set (received_lines ) - set (expected_lines )
@@ -257,8 +259,8 @@ def error_msg_for_unequal_output(
257
259
def _check_output_text (
258
260
self ,
259
261
_ : MessageCounter ,
260
- expected_output : List [OutputLine ],
261
- actual_output : List [OutputLine ],
262
+ expected_output : list [OutputLine ],
263
+ actual_output : list [OutputLine ],
262
264
) -> None :
263
265
"""This is a function because we want to be able to update the text in LintModuleOutputUpdate."""
264
266
assert expected_output == actual_output , self .error_msg_for_unequal_output (
0 commit comments