|
1 | 1 | # Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
2 | 2 | # For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
|
3 | 3 |
|
4 |
| -import collections |
5 | 4 | from typing import Any, NamedTuple, Optional, Sequence, Tuple, Union
|
6 | 5 |
|
7 | 6 | from astroid import nodes
|
|
12 | 11 | from pylint.testutils.constants import UPDATE_OPTION
|
13 | 12 |
|
14 | 13 |
|
15 |
| -class MessageTest( |
16 |
| - collections.namedtuple( |
17 |
| - "MessageTest", ["msg_id", "line", "node", "args", "confidence"] |
18 |
| - ) |
19 |
| -): |
| 14 | +class MessageTest(NamedTuple): |
20 | 15 | """Used to test messages produced by pylint. Class name cannot start with Test as pytest doesn't allow constructors in test classes."""
|
21 | 16 |
|
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 |
31 | 22 |
|
32 | 23 | def __eq__(self, other: object) -> bool:
|
33 | 24 | if isinstance(other, MessageTest):
|
34 | 25 | 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 |
37 | 28 | return NotImplemented # pragma: no cover
|
38 | 29 |
|
39 | 30 |
|
|
0 commit comments