forked from hardbyte/python-can
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypechecking.py
More file actions
38 lines (29 loc) · 1.16 KB
/
typechecking.py
File metadata and controls
38 lines (29 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"""Types for mypy type-checking
"""
import typing
if typing.TYPE_CHECKING:
import os
import mypy_extensions
CanFilter = mypy_extensions.TypedDict("CanFilter", {"can_id": int, "can_mask": int})
CanFilterExtended = mypy_extensions.TypedDict(
"CanFilterExtended", {"can_id": int, "can_mask": int, "extended": bool}
)
CanFilters = typing.Sequence[typing.Union[CanFilter, CanFilterExtended]]
# TODO: Once buffer protocol support lands in typing, we should switch to that,
# since can.message.Message attempts to call bytearray() on the given data, so
# this should have the same typing info.
#
# See: https://github.com/python/typing/issues/593
CanData = typing.Union[bytes, bytearray, int, typing.Iterable[int]]
# Used for the Abstract Base Class
ChannelStr = str
ChannelInt = int
Channel = typing.Union[ChannelInt, ChannelStr]
# Used by the IO module
FileLike = typing.IO[typing.Any]
StringPathLike = typing.Union[str, "os.PathLike[str]"]
AcceptedIOType = typing.Optional[typing.Union[FileLike, StringPathLike]]
BusConfig = typing.NewType("BusConfig", dict)
AutoDetectedConfig = mypy_extensions.TypedDict(
"AutoDetectedConfig", {"interface": str, "channel": Channel}
)