Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions can/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A little late but I don't really understand this. We only want to warn when extended_id=False is used but not extended_id=True?

And I think we should wait with issuing a warning until one or two versions later. Otherwise it won't be possible to support more than the latest python-can version without having thousands of warnings in the log.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or we could print a single warning per interpreter "session".

self.is_extended_id = extended_id

self.is_remote_frame = is_remote_frame
self.is_error_frame = is_error_frame
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions doc/message.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,18 @@ 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
>>> print(Message(extended_id=True))
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
Expand Down