diff --git a/can/message.py b/can/message.py index 57b61e34f..673bc3ca2 100644 --- a/can/message.py +++ b/can/message.py @@ -43,14 +43,14 @@ class Message(object): "is_fd", "bitrate_switch", "error_state_indicator", - "__weakref__", # support weak references to messages - "_dict" # see __getattr__ + "__weakref__", # support weak references to messages + "_dict" # see __getattr__ ) def __getattr__(self, key): # TODO keep this for a version, in order to not break old code # this entire method (as well as the _dict attribute in __slots__ and the __setattr__ method) - # can be removed in 3.0 + # can be removed in 4.0 # this method is only called if the attribute was not found elsewhere, like in __slots__ try: warnings.warn("Custom attributes of messages are deprecated and will be removed in the next major version", DeprecationWarning) @@ -68,20 +68,21 @@ def __setattr__(self, key, value): @property def id_type(self): - # TODO remove in 3.0 + # TODO remove in 4.0 warnings.warn("Message.id_type is deprecated, use is_extended_id", DeprecationWarning) return self.is_extended_id @id_type.setter def id_type(self, value): - # TODO remove in 3.0 + # TODO remove in 4.0 warnings.warn("Message.id_type is deprecated, use is_extended_id", DeprecationWarning) self.is_extended_id = value - def __init__(self, timestamp=0.0, arbitration_id=0, extended_id=True, + def __init__(self, timestamp=0.0, arbitration_id=0, is_extended_id=None, is_remote_frame=False, is_error_frame=False, channel=None, dlc=None, data=None, is_fd=False, bitrate_switch=False, error_state_indicator=False, + extended_id=True, check=False): """ To create a message object, simply provide any of the below attributes @@ -99,7 +100,13 @@ def __init__(self, timestamp=0.0, arbitration_id=0, extended_id=True, self.timestamp = timestamp self.arbitration_id = arbitration_id - self.is_extended_id = extended_id + if is_extended_id is not None: + self.is_extended_id = is_extended_id + else: + if not extended_id: + # Passed extended_id=False (default argument is True) so we warn to update + warnings.warn("extended_id is a deprecated parameter, use is_extended_id", DeprecationWarning) + self.is_extended_id = extended_id self.is_remote_frame = is_remote_frame self.is_error_frame = is_error_frame @@ -152,7 +159,7 @@ def __str__(self): if self.data is not None: for index in range(0, min(self.dlc, len(self.data))): data_strings.append("{0:02x}".format(self.data[index])) - if data_strings: # if not empty + if data_strings: # if not empty field_strings.append(" ".join(data_strings).ljust(24, " ")) else: field_strings.append(" " * 24) diff --git a/doc/message.rst b/doc/message.rst index e7e9fb353..fcb5e5e1a 100644 --- a/doc/message.rst +++ b/doc/message.rst @@ -103,6 +103,7 @@ Message :type: bool This flag controls the size of the :attr:`~can.Message.arbitration_id` field. + Previously this was exposed as `id_type`. >>> print(Message(extended_id=False)) Timestamp: 0.000000 ID: 0000 S DLC: 0 @@ -110,8 +111,10 @@ Message Timestamp: 0.000000 ID: 00000000 X DLC: 0 - Previously this was exposed as `id_type`. - Please use `is_extended_id` from now on. + .. note:: + + The :meth:`Message.__init__` argument ``extended_id`` has been deprecated in favor of + ``is_extended_id``, but will continue to work for the ``3.x`` release series. .. attribute:: is_error_frame