Skip to content

Commit 65f46cd

Browse files
committed
also enable mypy on the examples; this required two tiny changes somehwere else
1 parent 725bbd0 commit 65f46cd

4 files changed

Lines changed: 12 additions & 9 deletions

File tree

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ jobs:
104104
can/typechecking.py
105105
can/util.py
106106
can/io/**.py
107+
scripts/**.py
108+
examples/**.py
107109
- stage: linter
108110
name: "Formatting Checks"
109111
python: "3.7"

can/viewer.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
logger.warning(
4444
"You won't be able to use the viewer program without " "curses installed!"
4545
)
46-
curses = None
46+
curses = None # type: ignore
4747

4848

4949
class CanViewer:
@@ -153,7 +153,7 @@ def unpack_data(
153153
value = cmd_to_struct[key]
154154
if isinstance(value, tuple):
155155
# The struct is given as the fist argument
156-
struct_t = value[0] # type: struct.Struct
156+
struct_t: struct.Struct = value[0]
157157

158158
# The conversion from raw values to SI-units are given in the rest of the tuple
159159
values = [
@@ -162,8 +162,8 @@ def unpack_data(
162162
]
163163
else:
164164
# No conversion from SI-units is needed
165-
struct_t = value # type: struct.Struct
166-
values = list(struct_t.unpack(data))
165+
as_struct_t: struct.Struct = value
166+
values = list(as_struct_t.unpack(data))
167167

168168
return values
169169
else:

examples/cyclic_multiple.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def cyclic_multiple_send_modify(bus):
133133
for interface, channel in [("socketcan", "vcan0")]:
134134
print(f"Carrying out cyclic multiple tests with {interface} interface")
135135

136-
with can.Bus(interface=interface, channel=channel, bitrate=500000) as BUS:
136+
with can.Bus(interface=interface, channel=channel, bitrate=500000) as BUS: # type: ignore
137137
cyclic_multiple_send(BUS)
138138
cyclic_multiple_send_modify(BUS)
139139

examples/virtual_can_demo.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@
1010
import can
1111

1212

13-
def producer(thread_id, message_count=16):
13+
def producer(thread_id: int, message_count: int = 16):
1414
"""Spam the bus with messages including the data id.
1515
16-
:param int id: the id of the thread/process
16+
:param thread_id: the id of the thread/process
17+
:param message_count: the number of messages that shall be send
1718
"""
18-
with can.Bus(bustype="socketcan", channel="vcan0") as bus:
19+
with can.Bus(bustype="socketcan", channel="vcan0") as bus: # type: ignore
1920
for i in range(message_count):
2021
msg = can.Message(
21-
arbitration_id=0x0CF02200 + id, data=[thread_id, i, 0, 1, 3, 1, 4, 1]
22+
arbitration_id=0x0CF02200 + thread_id, data=[thread_id, i, 0, 1, 3, 1, 4, 1]
2223
)
2324
bus.send(msg)
2425
sleep(1.0)

0 commit comments

Comments
 (0)