-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Python modernization 2 #471
Conversation
web3/account.py
Outdated
return self.privateKeyToAccount(key_bytes) | ||
|
||
@staticmethod | ||
def decrypt(keyfile_json, password): | ||
if isinstance(keyfile_json, str) or ( | ||
sys.version_info.major < 3 and isinstance(keyfile_json, unicode)): # noqa: 821 | ||
if isinstance(keyfile_json, str): # noqa: 821 |
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.
Why noqa
here?
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.
@techtonik that was already in the code so I just left it there. I'm not sure what the comment is referencing.
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.
Just FYI, these noqa comments are a way of telling flake8
not to issue the specified warning. Most of the time it's best to fix the thing causing the warning, but occasionally the best thing to do is suppress it.
The list of warnings are here: http://flake8.pycqa.org/en/3.4.1/user/error-codes.html#error-violation-codes
821 is usage of an undefined name, which is usually pretty bad, but in this case it was just because unicode
isn't defined in py3, and we know a py3 codepath to that unicode
in this line is impossible.
Now that unicode
is removed, we can and should remove the warning supressor.
web3/account.py
Outdated
@@ -36,8 +35,7 @@ | |||
hexstr_if_str, | |||
text_if_str, | |||
to_bytes, | |||
to_int, | |||
to_hex, |
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.
👍
web3/utils/encoding.py
Outdated
In Python 2, only a unicode object will be interpreted as unicode text | ||
In Python 3, only a str object will be interpreted as interpreted as unicode text | ||
@param hexstr_or_primitive in bytes, str, or int. | ||
In Python 3, only a str object will be interpreted as unicode text |
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.
It is all Python 3 now.
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 guess its safe to delete all the "python 3" comments?
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.
👍
@@ -194,7 +193,6 @@ def to_bytes(primitive=None, hexstr=None, text=None): | |||
elif is_integer(primitive): | |||
return to_bytes(hexstr=to_hex(primitive)) | |||
elif hexstr is not None: | |||
hexstr = hexstr.rstrip('L') # handle longs in Python 2 |
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.
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.
fixed
Its failing in Travis on some weird
|
Looks like a pytest bug. The test name is being derived from the fixture values and the fixture has null bytes in it. Looks similar to pytest-dev/pytest#2644 |
@jasonrhaas work-around would be to to explicitely name the tests using one of these methods: https://docs.pytest.org/en/latest/example/parametrize.html#different-options-for-test-ids |
pytest-dev/pytest#2649 looks related. |
Used a list comprehension for `ids=` to work around this.
@pipermerriam I worked around this issue by assigning |
Hey, I've been reviewing and merging from oldest submissions to newest, and it looks like #456 did a lot of these same changes (hence the conflicts). I just took a pass at the conflicts, and will do a final review before merging... |
Pinning pytest to 3.2.5 also does the trick, but specifying ids also make the test results easier to read so I'm happy to see those in place 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.
Adding the ids is nice in some places (adds semantic value to the name of the test, like test_sig_bytes_chain_naive_v
).
In other places, it just obscures the test meaning, when it would be useful to see the names generated by inputs.
Now that the pinned pytest version doesn't have the null byte problem, let's keep the ids
that add semantic value, and remove the ones that obscure it.
@@ -56,6 +56,7 @@ | |||
('0xname.eth', 'address', True), # 0x in name is fine, if it is not a TLD | |||
('0xff', 'address', False), # but any valid hex starting with 0x should be rejected | |||
), | |||
ids=['test_' + str(x) for x in range(42)] |
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.
Since these ids
actually obscure the test results, let's just remove them now that pytest is pinned to 3.2.5.
@@ -18,7 +18,8 @@ | |||
(256, b'\x01\x00'), | |||
(True, b'\x01'), | |||
(False, b'\x00'), | |||
) | |||
), | |||
ids=['test_' + str(x) for x in range(10)] |
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.
The ids
in this module can go too (although the trailing comma on the list of args can stay).
tests/core/web3-module/test_sha3.py
Outdated
@@ -11,7 +11,8 @@ | |||
[ | |||
('cowmö', HexBytes('0x0f355f04c0a06eebac1d219b34c598f85a1169badee164be8a30345944885fe8')), | |||
('', HexBytes('0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470')), | |||
] | |||
], | |||
ids=['test_' + str(x) for x in range(2)] |
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.
These ids
can go too (although the trailing comma on the list of args can stay).
@carver this should be ready to merge once the Travis Tests finish running. |
What was wrong?
Finishing remaining items on #339.
How was it fixed?
Deleted old code.
Cute Animal Picture
hippo