Skip to content

Commit

Permalink
Make Message a dataclass
Browse files Browse the repository at this point in the history
  • Loading branch information
NickCao committed Aug 26, 2024
1 parent e291874 commit c0f1fb8
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions can/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@
This module contains the implementation of :class:`can.Message`.
.. note::
Could use `@dataclass <https://docs.python.org/3.7/library/dataclasses.html>`__
starting with Python 3.7.
Could use `@dataclass(slots=True, weakref_slot=True) <https://docs.python.org/3.11/library/dataclasses.html>`__
starting with Python 3.11.
"""

from copy import deepcopy
from dataclasses import dataclass
from math import isinf, isnan
from typing import Optional

from . import typechecking


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

timestamp: float
arbitration_id: int
is_extended_id: bool
is_remote_frame: bool
is_error_frame: bool
channel: Optional[typechecking.Channel]
dlc: Optional[int]
data: Optional[typechecking.CanData]
is_fd: bool
is_rx: bool
bitrate_switch: bool
error_state_indicator: bool

def __init__( # pylint: disable=too-many-locals, too-many-arguments
self,
timestamp: float = 0.0,
Expand Down

0 comments on commit c0f1fb8

Please sign in to comment.