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

Initial work towards adding type hints #656

Merged
merged 3 commits into from
Sep 10, 2018

Conversation

Zac-HD
Copy link
Member

@Zac-HD Zac-HD commented Sep 9, 2018

This PR contains some incremental work towards both #542 and #543. It's definitely not finished, but we found on Hypothesis (and on #594!) that merging this kind of thing in small pieces helps keep it moving 😄

There are basically four parts to this:

  • A fairly basic mypy.ini, with some notes on what to enable next
  • Copying the Simplify imports #594 approach for more imports
  • Completing pre-existing partial annotations
  • Moving property setters to immediately follow getters
    (Mypy has special-case code to understand them but it relies on proximity)

It does not run Mypy in CI, because there are still dozens of errors - many related to the highly-dynamic sockets module (not that the stdlib is more stable...).

@Zac-HD Zac-HD requested a review from njsmith September 9, 2018 06:51
@codecov
Copy link

codecov bot commented Sep 9, 2018

Codecov Report

Merging #656 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #656      +/-   ##
==========================================
- Coverage   99.32%   99.31%   -0.01%     
==========================================
  Files          94       94              
  Lines       11030    11011      -19     
  Branches      790      790              
==========================================
- Hits        10955    10936      -19     
  Misses         56       56              
  Partials       19       19
Impacted Files Coverage Δ
trio/testing/_mock_clock.py 100% <100%> (ø) ⬆️
trio/_sync.py 100% <100%> (ø) ⬆️
trio/testing/__init__.py 100% <100%> (ø) ⬆️
trio/_core/_ki.py 98.38% <100%> (ø) ⬆️
trio/_subprocess/unix_pipes.py 100% <100%> (ø) ⬆️
trio/_core/__init__.py 100% <100%> (ø) ⬆️
trio/testing/_sequencer.py 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 312b470...62ea141. Read the comment docs.

@njsmith
Copy link
Member

njsmith commented Sep 10, 2018

Yeah, socket is going to be a problem. It's probably fairly straightforward to clean up the functions, but for the constants, the set exported by python changes unpredictably between versions and build configurations, so I don't know that there is any way to avoid the dynamic re-export. Maybe we can just annotate the constants we use, or something...

Anyway, this looks good. Do you think there should be a release note, or should we wait until it's further along?

@Zac-HD
Copy link
Member Author

Zac-HD commented Sep 10, 2018

Yeah, socket is going to be a problem. ...

At some point downstream users are going to have to deal with that - I think the most sensible approach is for us to just ensure that all the names we use are visible to Mypy, and leave a very obvious comment on what's happening for anyone who resorts to reading the code.

Anyway, this looks good. Do you think there should be a release note, or should we wait until it's further along?

I wouldn't announce anything to users until we ship the PEP 561 py.typed marker, and they can use it. These issues are enough for contributors for now, but it might make sense to advertise it to potential contributors once Mypy is switched on in CI.

@Zac-HD Zac-HD merged commit 5d6ee81 into python-trio:master Sep 10, 2018
@Zac-HD Zac-HD deleted the start-type-hints branch September 10, 2018 05:21
@pquentin pquentin mentioned this pull request Sep 10, 2018
@njsmith
Copy link
Member

njsmith commented Sep 13, 2018

Staircase review: this should have fixed tab completion for trio.testing and trio._core... it'd be nice to extend the jedi/pylint tests to make sure that stays true :-)

(not that tab completion is very important for _core, but why not)

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.

3 participants