Skip to content

Commit d75a4ff

Browse files
committed
Dedupe some types into eth.typing
1 parent ba831fe commit d75a4ff

File tree

5 files changed

+47
-83
lines changed

5 files changed

+47
-83
lines changed

eth/chains/base.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import logging
2525

2626
from eth_typing import (
27-
Address,
2827
BlockNumber,
2928
Hash32,
3029
)
@@ -40,9 +39,6 @@
4039
iterate,
4140
take,
4241
)
43-
from mypy_extensions import (
44-
TypedDict,
45-
)
4642

4743
from eth.db.backends.base import BaseAtomicDB
4844
from eth.db.chain import (
@@ -103,20 +99,14 @@
10399
from eth.utils.rlp import (
104100
validate_imported_block_unchanged,
105101
)
102+
from eth.typing import (
103+
AccountState,
104+
)
106105

107106
if TYPE_CHECKING:
108107
from eth.vm.base import BaseVM # noqa: F401
109108

110109

111-
AccountDetails = TypedDict('AccountDetails',
112-
{'balance': int,
113-
'nonce': int,
114-
'code': bytes,
115-
'storage': Dict[int, int]
116-
})
117-
AccountState = Dict[Address, AccountDetails]
118-
119-
120110
class BaseChain(Configurable, ABC):
121111
"""
122112
The base class for all Chain objects

eth/tools/builder/chain/builders.py

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
Callable,
66
Dict,
77
Iterable,
8-
List,
98
Tuple,
109
Type,
11-
Union,
1210
)
1311

1412
from cytoolz import (
@@ -17,12 +15,7 @@
1715
pipe,
1816
)
1917

20-
from mypy_extensions import (
21-
TypedDict,
22-
)
23-
2418
from eth_typing import (
25-
Address,
2619
BlockNumber,
2720
)
2821

@@ -58,6 +51,10 @@
5851
from eth.tools._utils.normalization import (
5952
normalize_state,
6053
)
54+
from eth.typing import (
55+
AccountState,
56+
GeneralState,
57+
)
6158
from eth.validation import (
6259
validate_vm_configuration,
6360
)
@@ -77,19 +74,6 @@
7774
VMConfigurationType = Iterable[Tuple[int, Type[BaseVM]]]
7875

7976

80-
# 'balance', 'nonce' -> int
81-
# 'code' -> bytes
82-
# 'storage' -> Dict[int, int]
83-
AccountDetails = TypedDict('AccountDetails',
84-
{'balance': int,
85-
'nonce': int,
86-
'code': bytes,
87-
'storage': Dict[int, int]
88-
})
89-
AccountState = Dict[Address, AccountDetails]
90-
GeneralStateType = Union[AccountState, List[Tuple[Address, Dict[str, Union[int, bytes, Dict[int, int]]]]]] # noqa: E501
91-
92-
9377
def build(obj: Any, *applicators: Callable[..., Any]) -> Any:
9478
"""
9579
Run the provided object through the series of applicator functions.
@@ -343,7 +327,7 @@ def disable_pow_check(chain_class: Type[BaseChain]) -> type:
343327
#
344328
# Initializers (initialization of chain state and chain class instantiation)
345329
#
346-
def _fill_and_normalize_state(simple_state: GeneralStateType) -> AccountState:
330+
def _fill_and_normalize_state(simple_state: GeneralState) -> AccountState:
347331
base_state = normalize_state(simple_state)
348332
defaults = {address: {
349333
"balance": 0,
@@ -359,7 +343,7 @@ def _fill_and_normalize_state(simple_state: GeneralStateType) -> AccountState:
359343
def genesis(chain_class: BaseChain,
360344
db: BaseAtomicDB=None,
361345
params: Dict[str, HeaderParams]=None,
362-
state: GeneralStateType=None) -> BaseChain:
346+
state: GeneralState=None) -> BaseChain:
363347
"""
364348
Initialize the given chain class with the given genesis header parameters
365349
and chain state.

eth/typing.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from typing import (
2+
Dict,
3+
Iterable,
4+
List,
5+
Tuple,
6+
Union,
7+
)
8+
9+
from eth_typing import (
10+
Address,
11+
)
12+
from mypy_extensions import (
13+
TypedDict,
14+
)
15+
16+
17+
# TODO: Move into eth_typing
18+
19+
AccountDetails = TypedDict('AccountDetails',
20+
{'balance': int,
21+
'nonce': int,
22+
'code': bytes,
23+
'storage': Dict[int, int]
24+
})
25+
AccountState = Dict[Address, AccountDetails]
26+
27+
AccountDiff = Iterable[Tuple[Address, str, Union[int, bytes], Union[int, bytes]]]
28+
29+
GeneralState = Union[
30+
AccountState,
31+
List[Tuple[Address, Dict[str, Union[int, bytes, Dict[int, int]]]]]
32+
]

eth/utils/db.py

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,21 @@
11
from typing import (
2-
Dict,
32
TYPE_CHECKING,
43
)
54

6-
from mypy_extensions import (
7-
TypedDict,
8-
)
9-
105
from eth.db.account import (
116
BaseAccountDB,
127
)
138

149
from eth.rlp.headers import (
1510
BlockHeader,
1611
)
17-
18-
from eth_typing import (
19-
Address,
12+
from eth.typing import (
13+
AccountState,
2014
)
2115

2216
if TYPE_CHECKING:
2317
from eth.db.chain import BaseChainDB # noqa: F401
2418

25-
# 'balance', 'nonce' -> int
26-
# 'code' -> bytes
27-
# 'storage' -> Dict[int, int]
28-
AccountDetails = TypedDict('AccountDetails',
29-
{'balance': int,
30-
'nonce': int,
31-
'code': bytes,
32-
'storage': Dict[int, int]
33-
})
34-
AccountState = Dict[Address, AccountDetails]
35-
3619

3720
def get_parent_header(block_header: BlockHeader, db: 'BaseChainDB') -> BlockHeader:
3821
"""

eth/utils/state.py

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,14 @@
1-
from typing import (
2-
Dict,
3-
Iterable,
4-
Tuple,
5-
Union,
6-
)
7-
8-
from mypy_extensions import (
9-
TypedDict,
10-
)
11-
12-
from eth_typing import (
13-
Address,
14-
)
15-
161
from eth_utils import (
172
to_tuple,
183
)
194

205
from eth.db.account import (
216
BaseAccountDB,
227
)
23-
24-
25-
# 'balance', 'nonce' -> int
26-
# 'code' -> bytes
27-
# 'storage' -> Dict[int, int]
28-
AccountDetails = TypedDict('AccountDetails',
29-
{'balance': int,
30-
'nonce': int,
31-
'code': bytes,
32-
'storage': Dict[int, int]
33-
})
34-
AccountState = Dict[Address, AccountDetails]
35-
36-
AccountDiff = Iterable[Tuple[Address, str, Union[int, bytes], Union[int, bytes]]]
8+
from eth.typing import (
9+
AccountDiff,
10+
AccountState,
11+
)
3712

3813

3914
@to_tuple

0 commit comments

Comments
 (0)