Skip to content
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

Add type annotations #341

Merged
merged 8 commits into from Aug 8, 2021
Merged

Add type annotations #341

merged 8 commits into from Aug 8, 2021

Conversation

bluetech
Copy link
Member

@bluetech bluetech commented Aug 2, 2021

  • Annotate the package.
  • Annotate the tests.
  • Run mypy in CI (in both Python 2 and Python 3 modes).
  • Publish the types with py.typed files.

Fixes #339.

- Annotate the package.
- Annotate the tests.
- Run mypy in CI (in both Python 2 and Python 3 modes).
- Publish the types with `py.typed` files.

Fixes python-trio#339.
@codecov
Copy link

codecov bot commented Aug 4, 2021

Codecov Report

Merging #341 (a52a14e) into master (be5ec8a) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##            master      #341   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           10        10           
  Lines         1166      1186   +20     
  Branches        48        47    -1     
=========================================
+ Hits          1166      1186   +20     
Impacted Files Coverage Δ
trustme/__init__.py 100.00% <100.00%> (ø)
trustme/_cli.py 100.00% <100.00%> (ø)
trustme/tests/test_cli.py 100.00% <0.00%> (ø)
trustme/tests/test_trustme.py 100.00% <0.00%> (ø)
a/trustme/trustme/tests/test_cli.py 100.00% <0.00%> (ø)
a/trustme/trustme/tests/test_trustme.py 100.00% <0.00%> (ø)
...sers/runner/work/trustme/trustme/tests/test_cli.py 100.00% <0.00%> (ø)
.../runner/work/trustme/trustme/tests/test_trustme.py 100.00% <0.00%> (ø)

@pquentin
Copy link
Member

pquentin commented Aug 4, 2021

Thanks for tackling this!

That's a lot of ignores. :)

Can you please look into the Python 3 test failure?

@pquentin
Copy link
Member

pquentin commented Aug 5, 2021

I also enabled https://github.blog/changelog/2021-07-01-github-actions-new-settings-for-maintainers/ so that you won't have to wait for me to see the CI results.

@bluetech
Copy link
Member Author

bluetech commented Aug 5, 2021

That's a lot of ignores. :)

I didn't think so. Most of the ignores are for TypeError tests, where they are intentional. I hope one day to come back to python/mypy#8655 but don't get around to it.

Can you please look into the Python 3 test failure?

So the problem here is that mypy only runs on Python 3, so installs Python 3 dependencies, specifically pytest 6, but then mypy -2 fails with syntax errors. I'll sort it out somehow.

I also enabled https://github.blog/changelog/2021-07-01-github-actions-new-settings-for-maintainers/ so that you won't have to wait for me to see the CI results.

Thanks!

Avoid syntax errors when running `mypy -2`.
@pquentin
Copy link
Member

pquentin commented Aug 5, 2021

I'm happy with mypy only working on Python 3 if that helps!

@bluetech
Copy link
Member Author

bluetech commented Aug 5, 2021

I tried some more fixes but now there are two other problems:

  • mypy[python2] requires typed-ast which doesn't support PyPy.
  • pytest 4.6.x doesn't support Python 3.10

Possible solutions are:

  1. Have a dedicated mypy/lint job instead of running from ci.sh in each job. Probably a good idea anyway.
  2. Drop Python 2.

Since I already made the effort I'll go for 1, but we can do 2 as well in a (separate?) major release.

@pquentin
Copy link
Member

pquentin commented Aug 5, 2021

I like that plan. 👍

@bluetech
Copy link
Member Author

bluetech commented Aug 7, 2021

OK, I moved mypy to a separate lint jobs and left the CI job as is, seems to work.

For the coverage I added an exclude of if TYPE_CHECKING: but that doesn't seem to work in CI, even though it works locally, not sure why. I'll try to add explicit pragma: no cover maybe that will do the trick.

@bluetech
Copy link
Member Author

bluetech commented Aug 7, 2021

Codecov timed out earlier but it's green now. I'll work on dropping Python 2 next when I get a chance. I'll leave it to you to decide whether to do a final py2 release with typing or just go straight to py3.

@pquentin pquentin merged commit 5131f79 into python-trio:master Aug 8, 2021
@trio-bot
Copy link

trio-bot bot commented Aug 8, 2021

Hey @bluetech, it looks like that was the first time we merged one of your PRs! Thanks so much! 🎉 🎂

If you want to keep contributing, we'd love to have you. So, I just sent you an invitation to join the python-trio organization on Github! If you accept, then here's what will happen:

  • Github will automatically subscribe you to notifications on all our repositories. (But you can unsubscribe again if you don't want the spam.)

  • You'll be able to help us manage issues (add labels, close them, etc.)

  • You'll be able to review and merge other people's pull requests

  • You'll get a [member] badge next to your name when participating in the Trio repos, and you'll have the option of adding your name to our member's page and putting our icon on your Github profile (details)

If you want to read more, here's the relevant section in our contributing guide.

Alternatively, you're free to decline or ignore the invitation. You'll still be able to contribute as much or as little as you like, and I won't hassle you about joining again. But if you ever change your mind, just let us know and we'll send another invitation. We'd love to have you, but more importantly we want you to do whatever's best for you.

If you have any questions, well... I am just a humble Python script, so I probably can't help. But please do post a comment here, or in our chat, or on our forum, whatever's easiest, and someone will help you out!

@pquentin
Copy link
Member

pquentin commented Aug 8, 2021

Thanks! I don't have a strong opinion on including Python 2 removal in the next release or not. I just might not get to it before you.

@pquentin
Copy link
Member

@bluetech I just released 0.9.0 with this pull request

@bluetech bluetech deleted the typing branch August 13, 2021 09:40
@bluetech
Copy link
Member Author

@pquentin Thanks!

@hramezani FYI - urllib3 should be able to remove the type ignores for trustme now if it installs trustme>=0.9.0.

@hramezani
Copy link
Member

@bluetech Thanks for letting me know. Here is the PR urllib3/urllib3#2371

@bluetech bluetech mentioned this pull request Aug 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add typing
3 participants