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

Fix/ignore typing errors and add mypy to ci #38

Merged
merged 23 commits into from
May 15, 2022

Conversation

paiforsyth
Copy link
Contributor

@paiforsyth paiforsyth commented Apr 29, 2022

Thanks for this package! It looks like it could very useful!

I thought I would contribute by adding type checking.

  • Fix some typing errors
  • Ignore some other typing errors that seem to be caused by an incompatibility between the use of properties in this project and what mypy expects.
  • Add mypy to dev requirements
  • Add mypy to CI using invoke
  • Add invoke to dev requirements

I tried to add a mypy pre-commit hook, but this caused pre-commit CI to fail. I think this may be because the pre-commit CI is not able to install the correct requirements.

@codecov
Copy link

codecov bot commented Apr 29, 2022

Codecov Report

Merging #38 (c553065) into main (2c56d6a) will increase coverage by 1.99%.
The diff coverage is 96.96%.

@@            Coverage Diff             @@
##             main      #38      +/-   ##
==========================================
+ Coverage   91.74%   93.73%   +1.99%     
==========================================
  Files           6        6              
  Lines         339      351      +12     
==========================================
+ Hits          311      329      +18     
+ Misses         28       22       -6     
Impacted Files Coverage Δ
xarray_schema/dataarray.py 86.84% <94.44%> (+0.08%) ⬆️
xarray_schema/components.py 98.55% <100.00%> (+3.69%) ⬆️
xarray_schema/dataset.py 100.00% <100.00%> (+3.44%) ⬆️

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 2c56d6a...c553065. Read the comment docs.

@paiforsyth paiforsyth closed this Apr 29, 2022
@paiforsyth paiforsyth reopened this Apr 29, 2022
self.attrs = attrs
self.array_type = array_type
self.checks = checks
# see https://github.com/python/mypy/issues/3004
Copy link
Contributor Author

@paiforsyth paiforsyth Apr 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mypy seems to fail when it is applied to a property whose setter has a different return type than the parameter type of the corresponding getter. So I had to ignore these lines.

@paiforsyth paiforsyth changed the title Fix mypy Fix/ignore typing errors and add mypy to ci Apr 30, 2022
@paiforsyth paiforsyth closed this Apr 30, 2022
@paiforsyth paiforsyth reopened this Apr 30, 2022
@paiforsyth paiforsyth mentioned this pull request Apr 30, 2022
Copy link
Contributor

@jhamman jhamman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@paiforsyth - thank you for the contribution. This all looks great. Two small comments but otherwise all seems good.

@@ -27,7 +28,7 @@ def __init__(

self.data_vars = data_vars
self.coords = coords
self.attrs = attrs
self.attrs = AttrSchema(attrs)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the reason for needing to do this here, as opposed to in the setter?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've fixed this to use a setter

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, have you considered using dataclasses https://docs.python.org/3/library/dataclasses.html or attrs classes https://www.attrs.org/en/stable/ to represent schemas? They seem a natural fit.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

100% agree that we could transition to datacalsses. I may have even tried this in an earlier version. If memory serves, I ran into a problem with inheritance and decided to roll my own for the purposes of the MVP.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you'd like, we can discuss this idea in separate issue.

tasks.py Outdated Show resolved Hide resolved
@paiforsyth paiforsyth requested a review from jhamman May 3, 2022 01:03
@jhamman
Copy link
Contributor

jhamman commented May 12, 2022

closing and reopening to re-trigger codecov

@jhamman jhamman closed this May 12, 2022
@jhamman jhamman reopened this May 12, 2022
@paiforsyth
Copy link
Contributor Author

paiforsyth commented May 15, 2022

I had to mark tasks.py as ignored by coverage to pass the coverage check

@jhamman
Copy link
Contributor

jhamman commented May 15, 2022

Thanks @paiforsyth. I'm going to merge this now. Cheers!

@jhamman jhamman merged commit 9cbdae7 into xarray-contrib:main May 15, 2022
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.

2 participants