-
Notifications
You must be signed in to change notification settings - Fork 179
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
Replace attrdict with NamedTuple #76
Merged
pipermerriam
merged 2 commits into
ethereum:master
from
cburgdorf:christoph/refactor/named_tuple
Apr 21, 2020
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,36 @@ | ||
from attrdict import ( | ||
AttrDict, | ||
from typing import ( | ||
NamedTuple, | ||
) | ||
|
||
from hexbytes import ( | ||
HexBytes, | ||
) | ||
|
||
|
||
def __getitem__(self, index): | ||
try: | ||
return tuple.__getitem__(self, index) | ||
except TypeError: | ||
return getattr(self, index) | ||
|
||
|
||
class SignedTransaction(NamedTuple): | ||
rawTransaction: HexBytes | ||
hash: HexBytes | ||
r: int | ||
s: int | ||
v: int | ||
|
||
def __getitem__(self, index): | ||
return __getitem__(self, index) | ||
|
||
|
||
class SignedMessage(NamedTuple): | ||
messageHash: HexBytes | ||
r: int | ||
s: int | ||
v: int | ||
signature: HexBytes | ||
|
||
class AttributeDict(AttrDict): | ||
""" | ||
See `AttrDict docs <https://github.com/bcj/AttrDict#attrdict-1>`_ | ||
|
||
This class differs only in that it is made immutable. This immutability | ||
is **not** a security guarantee. It is only a style-check convenience. | ||
""" | ||
def __setitem__(self, attr, val): | ||
raise TypeError( | ||
'This data is immutable -- create a copy instead of modifying. ' | ||
'For example, AttributeDict(old, replace_key=replace_val).' | ||
) | ||
|
||
def _repr_pretty_(self, builder, cycle): | ||
""" | ||
Custom pretty output for the IPython console | ||
""" | ||
builder.text(self.__class__.__name__ + "(") | ||
if cycle: | ||
builder.text("<cycle>") | ||
else: | ||
builder.pretty(dict(self)) | ||
builder.text(")") | ||
def __getitem__(self, index): | ||
return __getitem__(self, index) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Interesting that the doctests (which were supposedly checked recently) didn't catch that the returned value changes below.
I would expect there to be a number of places in the docs where this would change.
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 just spent 1,5 hour to depuzzle this and here's the best I know so far:
We never had any doctest running in this repo so far. I wasn't able to find a single CI run that ran any doctests (even though they exist)
Then I found Doctests for Account and other general doc cleanup #94 which seems to fix this (it reports running 50 tests)
I'd happily rebase this on top of #94 but in case #94 needs more time to finish it should be easy to rebase that one on top of these changes, too.
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 totally lost track of #94. I just updated and it should be ready to merge. @cburgdorf I'm happy to pull your changes into #94, or vice versa, whatever is easier! Just let me know.
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.
@kclowes I don't have merge rights in this repo. If you have merge rights then feel free to merge both PRs in any preferred order.