Skip to content

Commit dd1614f

Browse files
committed
Tighten type of import_string
1 parent 61cef5c commit dd1614f

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

eth/db/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
from typing import (
33
Any,
4+
cast,
45
Type
56
)
67

@@ -20,7 +21,7 @@ def get_db_backend_class(import_path: str = None) -> Type[BaseAtomicDB]:
2021
'CHAIN_DB_BACKEND_CLASS',
2122
DEFAULT_DB_BACKEND,
2223
)
23-
return import_string(import_path)
24+
return cast(Type[BaseAtomicDB], import_string(import_path))
2425

2526

2627
def get_db_backend(import_path: str = None, **init_kwargs: Any) -> BaseAtomicDB:

eth/estimators/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
from typing import (
33
Callable,
4+
cast,
45
)
56

67
from eth.rlp.transactions import (
@@ -19,4 +20,4 @@ def get_gas_estimator() -> Callable[[BaseState, BaseTransaction], int]:
1920
'GAS_ESTIMATOR_BACKEND_FUNC',
2021
'eth.estimators.gas.binary_gas_search_intrinsic_tolerance',
2122
)
22-
return import_string(import_path)
23+
return cast(Callable[[BaseState, BaseTransaction], int], import_string(import_path))

eth/utils/module_loading.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import operator
22
from importlib import import_module
33

4+
from types import (
5+
ModuleType,
6+
)
47
from typing import (
5-
Any,
68
Tuple,
79
)
810

911

10-
def import_string(dotted_path: str) -> Any:
12+
def import_string(dotted_path: str) -> ModuleType:
1113
"""
1214
Source: django.utils.module_loading
1315
Import a dotted module path and return the attribute/class designated by the

0 commit comments

Comments
 (0)