Skip to content

Commit ba65bc0

Browse files
committed
Use typing.NamedTuple for MessageTest
1 parent 6900dae commit ba65bc0

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

pylint/testutils/output_line.py

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
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
5-
from typing import Any, NamedTuple
4+
from typing import Any, NamedTuple, Optional
5+
6+
from astroid import nodes
67

78
from pylint import interfaces
89
from pylint.constants import PY38_PLUS
10+
from pylint.interfaces import Confidence
911
from pylint.testutils.constants import UPDATE_OPTION
1012

1113

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

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
2122

2223
def __eq__(self, other):
2324
if isinstance(other, MessageTest):
2425
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
2728
return NotImplemented # pragma: no cover
2829

2930

0 commit comments

Comments
 (0)