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

Type checking with mypy #2655

Merged
merged 9 commits into from
Jan 8, 2019
Merged

Type checking with mypy #2655

merged 9 commits into from
Jan 8, 2019

Conversation

shoyer
Copy link
Member

@shoyer shoyer commented Jan 6, 2019

The rest of the scientific Python stack doesn't seem to support type annotations yet, but that's OK -- we can use this incrementally in xarray when it seems appropriate, and may check a few bugs. I'm especially excited to use this for internal functions, where we don't always bother with full docstrings (e.g., what is the type of the variables argument?).

This includes:

  1. various minor fixes to ensure that "mypy xarray" passes.
  2. adding "mypy xarray" to our lint check on Travis-CI.

For reference, see "Using mypy with an existing codebase":
https://mypy.readthedocs.io/en/stable/existing_code.html

Question: are we OK with (2)? This means Travis-CI will fail if your code causes mypy to error.

The rest of the scientific Python stack doesn't seem to support type
annotations yet, but that's OK -- we can use this incrementally in xarray when
it seems appropriate, and may check a few bugs. I'm especially excited to use
this for internal functions, where we don't always bother with full docstrings
(e.g., what is the type of the ``variables`` argument?).

This includes:
1. various minor fixes to ensure that "mypy xarray" passes.
2. adding "mypy xarray" to our lint check on Travis-CI.

For reference, see "Using mypy with an existing codebase":
https://mypy.readthedocs.io/en/stable/existing_code.html

Question: are we OK with (2)? This means Travis-CI will fail if your code
causes mypy to error.
@pep8speaks
Copy link

pep8speaks commented Jan 6, 2019

Hello @shoyer! Thanks for updating the PR.

Cheers ! There are no PEP8 issues in this Pull Request. 🍻

Comment last updated on January 07, 2019 at 01:08 Hours UTC

@shoyer shoyer mentioned this pull request Jan 6, 2019
3 tasks
@dcherian
Copy link
Contributor

dcherian commented Jan 6, 2019

Re (2): Perhaps it would be better to have mypy as an optional test?

Can you add some docs to the "contributing to xarray" section on how to annotate or link to some documentation so that contributors know where to look.

@shoyer
Copy link
Member Author

shoyer commented Jan 6, 2019

I agree, let's experiment with keeping mypy optional for now. The error messages can definitely be a little confusing for non-experts. It should be pretty easy to fix regressions as they come up.

I've added a brief note on mypy to the contributing docs and removed the Travis-CI check.

@shoyer
Copy link
Member Author

shoyer commented Jan 8, 2019

I think this is good to merge now

@shoyer shoyer merged commit 6963164 into pydata:master Jan 8, 2019
dcherian pushed a commit to dcherian/xarray that referenced this pull request Jan 14, 2019
* upstream/master:
  xfail cftimeindex multiindex test (pydata#2669)
  DOC: refresh "Why xarray" and shorten top-level description (pydata#2657)
  Remove broken Travis-CI builds (pydata#2661)
  Type checking with mypy (pydata#2655)
  Added Coarsen (pydata#2612)
dcherian pushed a commit to yohai/xarray that referenced this pull request Jan 24, 2019
* master:
  Remove broken Travis-CI builds (pydata#2661)
  Type checking with mypy (pydata#2655)
  Added Coarsen (pydata#2612)
  Improve test for GH 2649 (pydata#2654)
  revise top-level package description (pydata#2430)
  Convert ref_date to UTC in encode_cf_datetime (pydata#2651)
  Change an `==` to an `is`. Fix tests so that this won't happen again. (pydata#2648)
  ENH: switch Dataset and DataArray to use explicit indexes (pydata#2639)
  Use pycodestyle for lint checks. (pydata#2642)
  Switch whats-new for 0.11.2 -> 0.11.3
  DOC: document v0.11.2 release
  Use built-in interp for interpolation with resample (pydata#2640)
  BUG: pytest-runner no required for setup.py (pydata#2643)
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.

4 participants