Skip to content

Commit

Permalink
Use typing.NamedTuple for MessageTest
Browse files Browse the repository at this point in the history
  • Loading branch information
cdce8p committed Oct 7, 2021
1 parent 6fb5624 commit 165eebf
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions pylint/testutils/output_line.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE

import collections
from typing import Any, NamedTuple, Optional, Sequence, Tuple, Union

from astroid import nodes
Expand All @@ -12,28 +11,20 @@
from pylint.testutils.constants import UPDATE_OPTION


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

def __new__(
cls,
msg_id: str,
line: Optional[int] = None,
node: Optional[nodes.NodeNG] = None,
args: Any = None,
confidence: Optional[Confidence] = None,
) -> "MessageTest":
return tuple.__new__(cls, (msg_id, line, node, args, confidence))
msg_id: str
line: Optional[int] = None
node: Optional[nodes.NodeNG] = None
args: Any = None
confidence: Optional[Confidence] = None

def __eq__(self, other: object) -> bool:
if isinstance(other, MessageTest):
if self.confidence and other.confidence:
return super().__eq__(other)
return tuple(self[:-1]) == tuple(other[:-1])
return NamedTuple.__eq__(self, other)
return self[:-1] == other[:-1] # pylint: disable=unsubscriptable-object
return NotImplemented # pragma: no cover


Expand Down

0 comments on commit 165eebf

Please sign in to comment.