Skip to content

Commit c001ef2

Browse files
authored
Add typing annotations for SocketCAN interface (hardbyte#710)
Add typing annotations for the SocketCAN interface. This works towards PEP 561 compatibility.
1 parent 6945150 commit c001ef2

File tree

5 files changed

+131
-79
lines changed

5 files changed

+131
-79
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ jobs:
105105
can/broadcastmanager.py
106106
can/bus.py
107107
can/interface.py
108+
can/interfaces/socketcan/**.py
108109
can/listener.py
109110
can/logger.py
110111
can/message.py

can/bus.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Contains the ABC bus implementation and its documentation.
33
"""
44

5-
from typing import Iterator, List, Optional, Sequence, Tuple, Union
5+
from typing import cast, Iterator, List, Optional, Sequence, Tuple, Union
66

77
import can.typechecking
88

@@ -369,8 +369,10 @@ def _matches_filters(self, msg: Message) -> bool:
369369

370370
for _filter in self._filters:
371371
# check if this filter even applies to the message
372-
if "extended" in _filter and _filter["extended"] != msg.is_extended_id:
373-
continue
372+
if "extended" in _filter:
373+
_filter = cast(can.typechecking.CanFilterExtended, _filter)
374+
if _filter["extended"] != msg.is_extended_id:
375+
continue
374376

375377
# then check for the mask and id
376378
can_id = _filter["can_id"]
@@ -416,7 +418,7 @@ def state(self, new_state: BusState):
416418
raise NotImplementedError("Property is not implemented.")
417419

418420
@staticmethod
419-
def _detect_available_configs() -> Iterator[dict]:
421+
def _detect_available_configs() -> List[can.typechecking.AutoDetectedConfig]:
420422
"""Detect all configurations/channels that this interface could
421423
currently connect with.
422424

0 commit comments

Comments
 (0)