Skip to content

Commit 66a5d2a

Browse files
Add deprecation warning for 'bustype' parameter (#1462)
* deprecate bustype parameter * Add comment Co-authored-by: Felix Divo <[email protected]> Co-authored-by: Felix Divo <[email protected]>
1 parent 4136f37 commit 66a5d2a

26 files changed

+122
-122
lines changed

can/interface.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from typing import Any, cast, Iterable, Type, Optional, Union, List
1010

1111
from .bus import BusABC
12-
from .util import load_config
12+
from .util import load_config, deprecated_args_alias
1313
from .interfaces import BACKENDS
1414
from .exceptions import CanInterfaceNotImplementedError
1515
from .typechecking import AutoDetectedConfig, Channel
@@ -88,6 +88,7 @@ class Bus(BusABC): # pylint: disable=abstract-method
8888
"""
8989

9090
@staticmethod
91+
@deprecated_args_alias(bustype="interface") # Deprecated since python-can 4.2
9192
def __new__( # type: ignore # pylint: disable=keyword-arg-before-vararg
9293
cls: Any,
9394
channel: Optional[Channel] = None,

doc/bus.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ Example defining two filters, one to pass 11-bit ID ``0x451``, the other to pass
6969
{"can_id": 0x451, "can_mask": 0x7FF, "extended": False},
7070
{"can_id": 0xA0000, "can_mask": 0x1FFFFFFF, "extended": True},
7171
]
72-
bus = can.interface.Bus(channel="can0", bustype="socketcan", can_filters=filters)
72+
bus = can.interface.Bus(channel="can0", interface="socketcan", can_filters=filters)
7373
7474
7575
See :meth:`~can.BusABC.set_filters` for the implementation.

doc/configuration.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ You can also specify the interface and channel for each Bus instance::
3030

3131
import can
3232

33-
bus = can.interface.Bus(bustype='socketcan', channel='vcan0', bitrate=500000)
33+
bus = can.interface.Bus(interface='socketcan', channel='vcan0', bitrate=500000)
3434

3535

3636
Configuration File

doc/interfaces/gs_usb.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Usage: pass device ``index`` (starting from 0) if using automatic device detecti
1414

1515
import can
1616

17-
bus = can.Bus(bustype="gs_usb", channel=dev.product, index=0, bitrate=250000)
17+
bus = can.Bus(interface="gs_usb", channel=dev.product, index=0, bitrate=250000)
1818

1919
Alternatively, pass ``bus`` and ``address`` to open a specific device. The parameters can be got by ``pyusb`` as shown below:
2020

@@ -25,7 +25,7 @@ Alternatively, pass ``bus`` and ``address`` to open a specific device. The param
2525
2626
dev = usb.core.find(idVendor=0x1D50, idProduct=0x606F)
2727
bus = can.Bus(
28-
bustype="gs_usb",
28+
interface="gs_usb",
2929
channel=dev.product,
3030
bus=dev.bus,
3131
address=dev.address,

doc/interfaces/seeedstudio.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Interface
3131

3232
A bus example::
3333

34-
bus = can.interface.Bus(bustype='seeedstudio', channel='/dev/ttyUSB0', bitrate=500000)
34+
bus = can.interface.Bus(interface='seeedstudio', channel='/dev/ttyUSB0', bitrate=500000)
3535

3636

3737

doc/interfaces/socketcan.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,12 @@ To spam a bus:
177177
import time
178178
import can
179179
180-
bustype = 'socketcan'
180+
interface = 'socketcan'
181181
channel = 'vcan0'
182182
183183
def producer(id):
184184
""":param id: Spam the bus with messages including the data id."""
185-
bus = can.Bus(channel=channel, interface=bustype)
185+
bus = can.Bus(channel=channel, interface=interface)
186186
for i in range(10):
187187
msg = can.Message(arbitration_id=0xc0ffee, data=[id, i, 0, 1, 3, 1, 4, 1], is_extended_id=False)
188188
bus.send(msg)

doc/interfaces/socketcand.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ daemon running on a remote Raspberry Pi:
1818
1919
import can
2020
21-
bus = can.interface.Bus(bustype='socketcand', host="10.0.16.15", port=29536, channel="can0")
21+
bus = can.interface.Bus(interface='socketcand', host="10.0.16.15", port=29536, channel="can0")
2222
2323
# loop until Ctrl-C
2424
try:

doc/interfaces/udp_multicast.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ from ``bus_1`` to ``bus_2``:
4040
from can.interfaces.udp_multicast import UdpMulticastBus
4141
4242
# The bus can be created using the can.Bus wrapper class or using UdpMulticastBus directly
43-
with can.Bus(channel=UdpMulticastBus.DEFAULT_GROUP_IPv6, bustype='udp_multicast') as bus_1, \
43+
with can.Bus(channel=UdpMulticastBus.DEFAULT_GROUP_IPv6, interface='udp_multicast') as bus_1, \
4444
UdpMulticastBus(channel=UdpMulticastBus.DEFAULT_GROUP_IPv6) as bus_2:
4545
4646
# register a callback on the second bus that prints messages to the standard out

doc/interfaces/virtual.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ Example
1818
1919
import can
2020
21-
bus1 = can.interface.Bus('test', bustype='virtual')
22-
bus2 = can.interface.Bus('test', bustype='virtual')
21+
bus1 = can.interface.Bus('test', interface='virtual')
22+
bus2 = can.interface.Bus('test', interface='virtual')
2323
2424
msg1 = can.Message(arbitration_id=0xabcde, data=[1,2,3])
2525
bus1.send(msg1)
@@ -34,8 +34,8 @@ Example
3434
3535
import can
3636
37-
bus1 = can.interface.Bus('test', bustype='virtual', preserve_timestamps=True)
38-
bus2 = can.interface.Bus('test', bustype='virtual')
37+
bus1 = can.interface.Bus('test', interface='virtual', preserve_timestamps=True)
38+
bus2 = can.interface.Bus('test', interface='virtual')
3939
4040
msg1 = can.Message(timestamp=1639740470.051948, arbitration_id=0xabcde, data=[1,2,3])
4141

examples/asyncio_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def print_message(msg: can.Message) -> None:
1919
async def main() -> None:
2020
"""The main function that runs in the loop."""
2121

22-
with can.Bus( # type: ignore
22+
with can.Bus(
2323
interface="virtual", channel="my_channel_0", receive_own_messages=True
2424
) as bus:
2525
reader = can.AsyncBufferedReader()

0 commit comments

Comments
 (0)