-
Notifications
You must be signed in to change notification settings - Fork 223
Add type hints for base58.py #203
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
Conversation
Approach ACK! Can't go wrong with more type annotations. |
Concept Ack |
Concept ACK on type safety! @fanquake can you force push a trivial change when you're released from Travis prison? |
@Sjors I've force pushed a change. |
The project is actually listed as allowing Python 3.5.6, so I believe this would break that. However I wouldn't be opposed to bumping the minimum to 3.6. Also needs rebase. |
Concept ACK: Python without type hints is like driving without a safety belt :-) (Like C++ without the sanitisers or static analysis!) |
Tried using Python 3.5.6, our current minimum, and got:
|
.travis.yml
Outdated
@@ -54,6 +54,8 @@ jobs: | |||
- name: lint | |||
stage: lint | |||
script: flake8 | |||
- name: Type annotation checking | |||
script: poetry run mypy hwilib/base58.py |
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.
Could you add an install
phase that just installs mypy
and whatever else is needed to run the check?
We don't need to do the full install phase since that does a bunch of things unneeded for linters. See #261
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.
Updated to use an install
phase, and dropped the mypy
dev dependency.
If you're still happy to bump the minimum Python version to 3.6.x, I can do that here. Otherwise I can propose it in a separate PR? |
d6b1d09 Bump minimum python version to 3.6 (Andrew Chow) Pull request description: Needed for #203 This is not expected to impact existing projects using HWI. AFAIK there are only two projects that use HWI, [Wasabi Wallet](https://github.com/zkSNACKs/WalletWasabi) and [Junction](https://github.com/justinmoon/junction). Wasabi use the binary distribution so it is not effected. Junction also requires 3.6+. ACKs for top commit: fanquake: ACK d6b1d09 - will rebase #203 afterwards. Tree-SHA512: 147e2a24962b3bb85566468836b99ae25719d2ff4208711d0ca26b27cd7301efec050a44234184911bbe9e703a0b2a661d36b69e098ce4a3dc642e9b53027251
ACK b739f38 |
1 similar comment
ACK b739f38 |
b739f38 travis: add mypy lint job (fanquake) 06fa997 base58: add type hints (fanquake) 394dab3 base58: remove Python3 check (fanquake) a2edbf1 test: Add base58 tests (fanquake) Pull request description: TLDR: This add type hints to base58.py, as well as some basic tests and a Travis job that runs [`mypy`](http://mypy-lang.org). This adds some simple base58 tests (copied from the Bitcoin Core repo), [type hints](https://docs.python.org/3.6/library/typing.html) for base58.py and a Travis job that runs `mypy` on base58.py. I started with base58.py to keep everything self contained. `mypy` was added as a dev dependency using `poetry add mypy --dev`. Given that the project is using > Python 3.6, we can also take advantage [variable type annotations](https://www.python.org/dev/peps/pep-0526/). Just opening as a draft for some concept level discussion. If there is interested then more anntotations can be added, and the Travis `mypy` scope increased. If we are happy to add type annotations here, then I'll PR the same changes to any upstream libraries, i.e [`bech32.py`](https://github.com/sipa/bech32/blob/master/ref/python/segwit_addr.py). Another good reference for type hints is: https://mypy.readthedocs.io/en/latest/cheat_sheet_py3.html ACKs for top commit: laanwj: ACK b739f38 achow101: ACK b739f38 Tree-SHA512: 839822b75756a2cd6d3595988d8bbe2cce962a344b71d2abc4d5b410a4161f3ad98c8aa35881fd148c0c0646e146d8942fa4a5f69f4ddf990da9d00599d7df39
TLDR: This add type hints to base58.py, as well as some basic tests and a Travis job that runs
mypy
.This adds some simple base58 tests (copied from the Bitcoin Core repo), type hints for base58.py and a Travis job that runs
mypy
on base58.py. I started with base58.py to keep everything self contained.mypy
was added as a dev dependency usingpoetry add mypy --dev
.Given that the project is using > Python 3.6, we can also take advantage variable type annotations.
Just opening as a draft for some concept level discussion. If there is interested then more anntotations can be added, and the Travis
mypy
scope increased. If we are happy to add type annotations here, then I'll PR the same changes to any upstream libraries, i.ebech32.py
.Another good reference for type hints is: https://mypy.readthedocs.io/en/latest/cheat_sheet_py3.html