• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hardbyte / python-can / 16465853887

23 Jul 2025 08:42AM UTC coverage: 71.213% (-0.07%) from 71.278%
16465853887

push

github

web-flow
Improve can.io type annotations (#1951)

166 of 186 new or added lines in 11 files covered. (89.25%)

5 existing lines in 1 file now uncovered.

7842 of 11012 relevant lines covered (71.21%)

13.61 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.15
/can/typechecking.py
1
"""Types for mypy type-checking"""
21✔
2

3
import io
21✔
4
import sys
21✔
5
from collections.abc import Iterable, Sequence
21✔
6
from typing import IO, TYPE_CHECKING, Any, NewType, Union
21✔
7

8
if sys.version_info >= (3, 10):
21✔
9
    from typing import TypeAlias
15✔
10
else:
11
    from typing_extensions import TypeAlias
6✔
12

13
if sys.version_info >= (3, 12):
21✔
14
    from typing import TypedDict
6✔
15
else:
16
    from typing_extensions import TypedDict
15✔
17

18

19
if TYPE_CHECKING:
21✔
20
    import os
×
NEW
21
    import struct
×
22

23

24
class CanFilter(TypedDict):
21✔
25
    can_id: int
21✔
26
    can_mask: int
21✔
27

28

29
class CanFilterExtended(TypedDict):
21✔
30
    can_id: int
21✔
31
    can_mask: int
21✔
32
    extended: bool
21✔
33

34

35
CanFilters = Sequence[Union[CanFilter, CanFilterExtended]]
21✔
36

37
# TODO: Once buffer protocol support lands in typing, we should switch to that,
38
# since can.message.Message attempts to call bytearray() on the given data, so
39
# this should have the same typing info.
40
#
41
# See: https://github.com/python/typing/issues/593
42
CanData = Union[bytes, bytearray, int, Iterable[int]]
21✔
43

44
# Used for the Abstract Base Class
45
ChannelStr = str
21✔
46
ChannelInt = int
21✔
47
Channel = Union[ChannelInt, ChannelStr, Sequence[ChannelInt]]
21✔
48

49
# Used by the IO module
50
FileLike = Union[IO[Any], io.TextIOWrapper, io.BufferedIOBase]
21✔
51
StringPathLike = Union[str, "os.PathLike[str]"]
21✔
52

53
BusConfig = NewType("BusConfig", dict[str, Any])
21✔
54

55
# Used by CLI scripts
56
TAdditionalCliArgs: TypeAlias = dict[str, Union[str, int, float, bool]]
21✔
57
TDataStructs: TypeAlias = dict[
21✔
58
    Union[int, tuple[int, ...]],
59
    "Union[struct.Struct, tuple[struct.Struct, *tuple[float, ...]]]",
60
]
61

62

63
class AutoDetectedConfig(TypedDict):
21✔
64
    interface: str
21✔
65
    channel: Channel
21✔
66

67

68
ReadableBytesLike = Union[bytes, bytearray, memoryview]
21✔
69

70

71
class BitTimingDict(TypedDict):
21✔
72
    f_clock: int
21✔
73
    brp: int
21✔
74
    tseg1: int
21✔
75
    tseg2: int
21✔
76
    sjw: int
21✔
77
    nof_samples: int
21✔
78

79

80
class BitTimingFdDict(TypedDict):
21✔
81
    f_clock: int
21✔
82
    nom_brp: int
21✔
83
    nom_tseg1: int
21✔
84
    nom_tseg2: int
21✔
85
    nom_sjw: int
21✔
86
    data_brp: int
21✔
87
    data_tseg1: int
21✔
88
    data_tseg2: int
21✔
89
    data_sjw: int
21✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc