Skip to content

Commit be08bc6

Browse files
committed
fix typing
1 parent d5454e0 commit be08bc6

2 files changed

Lines changed: 17 additions & 13 deletions

File tree

‎can/typechecking.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
StringPathLike = typing.Union[str, "os.PathLike[str]"]
3232
AcceptedIOType = typing.Optional[typing.Union[FileLike, StringPathLike]]
3333

34-
BusConfig = typing.NewType("BusConfig", dict)
34+
BusConfig = typing.NewType("BusConfig", typing.Dict[str, typing.Any])
3535

3636
AutoDetectedConfig = mypy_extensions.TypedDict(
3737
"AutoDetectedConfig", {"interface": str, "channel": Channel}

‎can/util.py‎

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import functools
66
import warnings
7-
from typing import Any, Dict, Tuple, Optional
7+
from typing import Any, Callable, cast, Dict, Iterable, List, Tuple, Optional, Union
88
from time import time, perf_counter, get_clock_info
99
import json
1010
import os
@@ -156,16 +156,19 @@ def load_config(
156156
config = {}
157157

158158
# use the given dict for default values
159-
config_sources = [
160-
given_config,
161-
can.rc,
162-
lambda _context: load_environment_config( # pylint: disable=unnecessary-lambda
163-
_context
164-
),
165-
lambda _context: load_environment_config(),
166-
lambda _context: load_file_config(path, _context),
167-
lambda _context: load_file_config(path),
168-
]
159+
config_sources = cast(
160+
Iterable[Union[Dict[str, Any], Callable[[Any], Dict[str, Any]]]],
161+
[
162+
given_config,
163+
can.rc,
164+
lambda _context: load_environment_config( # pylint: disable=unnecessary-lambda
165+
_context
166+
),
167+
lambda _context: load_environment_config(),
168+
lambda _context: load_file_config(path, _context),
169+
lambda _context: load_file_config(path),
170+
],
171+
)
169172

170173
# Slightly complex here to only search for the file config if required
171174
for cfg in config_sources:
@@ -216,7 +219,8 @@ def load_config(
216219
config["timing"] = can.BitTiming(**timing_conf)
217220

218221
can.log.debug("can config: %s", config)
219-
return config
222+
223+
return cast(typechecking.BusConfig, config)
220224

221225

222226
def set_logging_level(level_name: str) -> None:

0 commit comments

Comments
 (0)