Skip to content

Commit c0f1fb8

Browse files
committed
Make Message a dataclass
1 parent e291874 commit c0f1fb8

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

can/message.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@
22
This module contains the implementation of :class:`can.Message`.
33
44
.. note::
5-
Could use `@dataclass <https://docs.python.org/3.7/library/dataclasses.html>`__
6-
starting with Python 3.7.
5+
Could use `@dataclass(slots=True, weakref_slot=True) <https://docs.python.org/3.11/library/dataclasses.html>`__
6+
starting with Python 3.11.
77
"""
88

99
from copy import deepcopy
10+
from dataclasses import dataclass
1011
from math import isinf, isnan
1112
from typing import Optional
1213

1314
from . import typechecking
1415

1516

17+
@dataclass
1618
class Message: # pylint: disable=too-many-instance-attributes; OK for a dataclass
1719
"""
1820
The :class:`~can.Message` object is used to represent CAN messages for
@@ -47,6 +49,19 @@ class Message: # pylint: disable=too-many-instance-attributes; OK for a datacla
4749
"__weakref__", # support weak references to messages
4850
)
4951

52+
timestamp: float
53+
arbitration_id: int
54+
is_extended_id: bool
55+
is_remote_frame: bool
56+
is_error_frame: bool
57+
channel: Optional[typechecking.Channel]
58+
dlc: Optional[int]
59+
data: Optional[typechecking.CanData]
60+
is_fd: bool
61+
is_rx: bool
62+
bitrate_switch: bool
63+
error_state_indicator: bool
64+
5065
def __init__( # pylint: disable=too-many-locals, too-many-arguments
5166
self,
5267
timestamp: float = 0.0,

0 commit comments

Comments
 (0)