-
Notifications
You must be signed in to change notification settings - Fork 685
Christoph/fix/typehints #1412
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Christoph/fix/typehints #1412
Conversation
bf9dfb0
to
590668a
Compare
eth/tools/builder/chain/builders.py
Outdated
|
||
VMConfigurationType = Iterable[Tuple[int, Type[BaseVM]]] | ||
GeneralStateType = Union[AccountState, List[Tuple[Address, Dict[str, Union[int, bytes, Dict[int, int]]]]]] # noqa: E501 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the inner Dict
should be updated to be an AccountDetals
.
|
||
# TODO: Move into eth_typing | ||
|
||
AccountDetails = TypedDict('AccountDetails', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooooh! TypedDict
is cool.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, they let us avoid sprinkling the code with assert
statements #1404 (comment)
eth/utils/module_loading.py
Outdated
|
||
def import_string(dotted_path): | ||
|
||
def import_string(dotted_path: str) -> Any: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you use types.ModuleType
here instead of Any
?
eth/utils/numeric.py
Outdated
@@ -12,7 +15,7 @@ | |||
) | |||
|
|||
|
|||
def int_to_bytes32(value): | |||
def int_to_bytes32(value: Union[int, bool]) -> bytes: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think Hash32
is more appropriate than bytes
eth/utils/transactions.py
Outdated
def create_transaction_signature(unsigned_txn, private_key, chain_id=None): | ||
def create_transaction_signature(unsigned_txn: BaseTransaction, | ||
private_key: datatypes.PrivateKey, | ||
chain_id: int=None) -> Tuple[int, int, int]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
candidate for eth-typing VRS = NewType("VRS", Tuple[int, int, int])
also, UINT256 = NewType("UINT256", int)
for these values that are specifically bounded within the 256 bit integer space.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So VRS
would then be a VRS = NewType("VRS", Tuple[UINT256, UINT256, UINT256])
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, though v
might have a lower ceiling than the others (not sure what it is, might be a single byte).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't talk low level math with me! What does v
even stand for? Vitalik? ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://bitcoin.stackexchange.com/questions/38351/ecdsa-v-r-s-what-is-v/38909
v
is the recovery id and looks to be reasonably bounded within a single byte (2**8 or UINT8
)
a649738
to
d75a4ff
Compare
7d5e5ad
to
141a415
Compare
141a415
to
e27638a
Compare
@Bhargavasomu thanks again for doing the bulk of the work! You may want to check out the few extra commits on top just to get a feel what kind of changes were made. |
@@ -45,7 +45,7 @@ commands= | |||
native-state-metropolis: pytest {posargs:tests/json-fixtures/test_state.py -k Metropolis} | |||
lightchain_integration: pytest --integration {posargs:tests/trinity/integration/test_lightchain_integration.py} | |||
|
|||
deps = .[p2p,trinity,eth-extra,test] | |||
deps = .[eth,p2p,trinity,eth-extra,test] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is confusing to me: .
should already be installing those packages:
https://github.com/cburgdorf/py-evm/blob/db8bf2e1003bb18542a3e36ff46fbffabfddc808/setup.py#L102
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for pointing that out, now I'm confused as well. Let's see #1417
@@ -12,6 +12,7 @@ | |||
"eth-typing>=2.0.0,<3.0.0", | |||
"eth-utils>=1.3.0b0,<2.0.0", | |||
"lru-dict>=1.1.6", | |||
"mypy_extensions>=0.4.1,<1.0.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feels a little weird, like including flake8
in the distribution. Don't feel strongly about it though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At the end of the day, mypy_extensions
is a library as any other and we are using it now for things like TypedDict
. Notice that this is not just a type hint per se. We have to have it in order for code such as the following to work.
Lines 20 to 25 in 7ad4259
AccountDetails = TypedDict('AccountDetails', | |
{'balance': int, | |
'nonce': int, | |
'code': bytes, | |
'storage': Dict[int, int] | |
}) |
@cburgdorf I noticed that you have moved some type definitions to |
Yep, and in the long run we might move some if not all to https://github.com/ethereum/eth-typing |
This is mostly #1404 by @Bhargavasomu with some minimal fine tuning on top.
What was wrong?
The
eth
module was nottype hinted
till now. This needs to be fixed and also thetox.ini
file needs to be updated.Issue : #1398
How was it fixed?
Adding
type hints
to the arguments and the function. The phase of adding the type hints is as followsCute Animal Picture