|
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 |
| -from typing import Any, NamedTuple |
| 4 | +from typing import Any, NamedTuple, Optional |
| 5 | + |
| 6 | +from astroid import nodes |
6 | 7 |
|
7 | 8 | from pylint import interfaces
|
8 | 9 | from pylint.constants import PY38_PLUS
|
| 10 | +from pylint.interfaces import Confidence |
9 | 11 | from pylint.testutils.constants import UPDATE_OPTION
|
10 | 12 |
|
11 | 13 |
|
12 |
| -class MessageTest( |
13 |
| - collections.namedtuple( |
14 |
| - "MessageTest", ["msg_id", "line", "node", "args", "confidence"] |
15 |
| - ) |
16 |
| -): |
| 14 | +class MessageTest(NamedTuple): |
17 | 15 | """Used to test messages produced by pylint. Class name cannot start with Test as pytest doesn't allow constructors in test classes."""
|
18 | 16 |
|
19 |
| - def __new__(cls, msg_id, line=None, node=None, args=None, confidence=None): |
20 |
| - 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 |
21 | 22 |
|
22 | 23 | def __eq__(self, other):
|
23 | 24 | if isinstance(other, MessageTest):
|
24 | 25 | if self.confidence and other.confidence:
|
25 |
| - return super().__eq__(other) |
26 |
| - return self[:-1] == other[:-1] |
| 26 | + return NamedTuple.__eq__(self, other) |
| 27 | + return self[:-1] == other[:-1] # pylint: disable=unsubscriptable-object |
27 | 28 | return NotImplemented # pragma: no cover
|
28 | 29 |
|
29 | 30 |
|
|
0 commit comments