dev: change type of branch node subnodes#1066
Conversation
bcef93c to
2a3b61a
Compare
|
Does the annotation get enforced? If not, I'd prefer the tuple with 16 elements, probably as a proper type or type alias. |
|
The Annotation is not enforced. It's only a "hint" for the reader that it expects 16 elements. We could create a proper type that Perhaps something like: |
|
Kinda ugly, but I don't see a shorter way of making the type annotation meaningful to mypy. Let's go with the sixteen |
|
done :) |
|
Hi @SamWilsn, any chance you can help me understand why CI is failing ? |
|
Re-ran it and it seems to be passing now. The error wasn't something I've ever seen before, so I'm hoping it's just something weird on our github runner. |
|
I think avoiding the |
|
merged it @SamWilsn :) |
|
This passed for me. I'll dig into this a bit. I bet it's something to do with my local Python version. |
|
Fixed: kkrt-labs#2 |
* dev: change type of branch node subnodes * Annotate tuple with 16 * add ellipsis to tuple * explicit tuple * use explicit 16-field tuple * fmt * remove Annotated import * fix types * Use assert_type alongside cast (#1) * Import from typing_extensions instead of typing (#2) --------- Co-authored-by: Sam Wilson <57262657+SamWilsn@users.noreply.github.com>
* dev: change type of branch node subnodes * Annotate tuple with 16 * add ellipsis to tuple * explicit tuple * use explicit 16-field tuple * fmt * remove Annotated import * fix types * Use assert_type alongside cast (ethereum#1) * Import from typing_extensions instead of typing (ethereum#2) --------- Co-authored-by: Sam Wilson <57262657+SamWilsn@users.noreply.github.com>
* dev: change type of branch node subnodes * Annotate tuple with 16 * add ellipsis to tuple * explicit tuple * use explicit 16-field tuple * fmt * remove Annotated import * fix types * Use assert_type alongside cast (ethereum#1) * Import from typing_extensions instead of typing (ethereum#2) --------- Co-authored-by: Sam Wilson <57262657+SamWilsn@users.noreply.github.com>
What was wrong?
The type for the BranchNode's subnodes was
List[rlp.Extended]. While this is not inherently wrong, a more suitable type would be a tuple with 16 rlp.Extended elements, each representing a BranchNode of the trie, as there's no intent to mutate the subnodes after instantiation.Related to Issue #
How was it fixed?
Changed to
Annotated[Tuple[rlp.Extended, ...], 16]. Also open to just repeating 16 times the rlp.Extended argument, but using an annotation sounds more convenient rather than repeating. The annotation conveys at type hint that the tuple is of size 16.Cute Animal Picture
Our beloved moodeng friend
