Skip to content

Commit 165eebf

Browse files
committed
Use typing.NamedTuple for MessageTest
1 parent 6fb5624 commit 165eebf

File tree

1 file changed

+8
-17
lines changed

1 file changed

+8
-17
lines changed

pylint/testutils/output_line.py

+8-17
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
33

4-
import collections
54
from typing import Any, NamedTuple, Optional, Sequence, Tuple, Union
65

76
from astroid import nodes
@@ -12,28 +11,20 @@
1211
from pylint.testutils.constants import UPDATE_OPTION
1312

1413

15-
class MessageTest(
16-
collections.namedtuple(
17-
"MessageTest", ["msg_id", "line", "node", "args", "confidence"]
18-
)
19-
):
14+
class MessageTest(NamedTuple):
2015
"""Used to test messages produced by pylint. Class name cannot start with Test as pytest doesn't allow constructors in test classes."""
2116

22-
def __new__(
23-
cls,
24-
msg_id: str,
25-
line: Optional[int] = None,
26-
node: Optional[nodes.NodeNG] = None,
27-
args: Any = None,
28-
confidence: Optional[Confidence] = None,
29-
) -> "MessageTest":
30-
return tuple.__new__(cls, (msg_id, line, node, args, confidence))
17+
msg_id: str
18+
line: Optional[int] = None
19+
node: Optional[nodes.NodeNG] = None
20+
args: Any = None
21+
confidence: Optional[Confidence] = None
3122

3223
def __eq__(self, other: object) -> bool:
3324
if isinstance(other, MessageTest):
3425
if self.confidence and other.confidence:
35-
return super().__eq__(other)
36-
return tuple(self[:-1]) == tuple(other[:-1])
26+
return NamedTuple.__eq__(self, other)
27+
return self[:-1] == other[:-1] # pylint: disable=unsubscriptable-object
3728
return NotImplemented # pragma: no cover
3829

3930

0 commit comments

Comments
 (0)