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 typing errors using mypy 1.2 #7752

Merged
merged 15 commits into from
Apr 15, 2023
Merged

Conversation

Illviljan
Copy link
Contributor

@Illviljan Illviljan commented Apr 12, 2023

Fixes typing errors when using newest mypy version.

@github-actions github-actions bot added the Automation Github bots, testing workflows, release automation label Apr 12, 2023
@Illviljan
Copy link
Contributor Author

Before:

 xarray/core/utils.py:116: error: Unused "type: ignore" comment
xarray/core/combine.py:374: error: Unused "type: ignore" comment
xarray/core/rolling.py:379: error: Unused "type: ignore" comment
xarray/core/rolling.py:756: error: Unused "type: ignore" comment
xarray/tests/test_plot.py:2045: error: Argument "col" has incompatible type "str"; expected "None"  [arg-type]
xarray/tests/test_plot.py:2054: error: Argument "col" has incompatible type "str"; expected "None"  [arg-type]
xarray/tests/test_variable.py:65: error: "staticmethod" expects 2 type arguments, but 1 given  [type-arg]
xarray/tests/test_concat.py:543: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
Generated Cobertura report: /home/runner/work/xarray/xarray/mypy_report/cobertura.xml
Installing missing stub packages:
/home/runner/micromamba-root/envs/xarray-tests/bin/python -m pip install types-PyYAML types-Pygments types-babel types-colorama types-paramiko types-psutil types-pytz types-pywin32 types-setuptools types-urllib3


Generated Cobertura report: /home/runner/work/xarray/xarray/mypy_report/cobertura.xml
Found 7 errors in 5 files (checked 138 source files)

@github-actions github-actions bot added topic-combine combine/concat/merge topic-rolling labels Apr 12, 2023
@Illviljan
Copy link
Contributor Author

Illviljan commented Apr 14, 2023

The mypy 3.9 CI keeps installing the old version which hinders installing a new version with python -m pip install mypy.

INSTALLED VERSIONS
------------------
commit: c6eeaa6faa0f3d084f98bb5c9bad777533f07a40
python: 3.9.16 | packaged by conda-forge | (main, Feb  1 2023, 21:39:03) 
[GCC 11.3.0]
python-bits: 64
OS: Linux
OS-release: 5.15.0-1035-azure
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: C.UTF-8
LOCALE: ('en_US', 'UTF-8')
libhdf5: 1.12.2
libnetcdf: 4.9.1

xarray: 2023.3.1.dev56+gc6eeaa6f
pandas: 2.0.0
numpy: 1.23.5
scipy: 1.10.1
netCDF4: 1.6.3
pydap: installed
h5netcdf: 1.1.0
h5py: 3.8.0
Nio: None
zarr: 2.14.2
cftime: 1.6.2
nc_time_axis: 1.4.1
PseudoNetCDF: 3.2.2
iris: 3.4.1
bottleneck: 1.3.7
dask: 2023.3.2
distributed: 2023.3.2.1
matplotlib: 3.7.1
cartopy: 0.21.1
seaborn: 0.12.2
numbagg: 0.2.2
fsspec: 2023.4.0
cupy: None
pint: 0.20.1
sparse: 0.14.0
flox: 0.6.10
numpy_groupies: 0.9.20
setuptools: 67.6.1
pip: 23.0.1
conda: 23.3.1
pytest: 7.3.0
mypy: 0.982
IPython: None
sphinx: None

Using python -m pip install mypy --force-reinstall seems to do the trick.

@Illviljan Illviljan changed the title test newest mypy Fix typing errors using mypy 1.2 Apr 14, 2023
@Illviljan Illviljan marked this pull request as ready for review April 14, 2023 20:43
@dcherian dcherian requested a review from headtr1ck April 15, 2023 01:18
Copy link
Collaborator

@headtr1ck headtr1ck left a comment

Choose a reason for hiding this comment

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

Thanks! Looks good to me.

Does this fix #7270?

xarray/core/combine.py Outdated Show resolved Hide resolved
@headtr1ck headtr1ck added topic-typing and removed topic-rolling topic-combine combine/concat/merge labels Apr 15, 2023
@github-actions github-actions bot added topic-combine combine/concat/merge topic-rolling labels Apr 15, 2023
@@ -2042,7 +2042,7 @@ def test_seaborn_palette_as_cmap(self) -> None:
def test_convenient_facetgrid(self) -> None:
a = easy_array((10, 15, 4))
d = DataArray(a, dims=["y", "x", "z"])
g = self.plotfunc(d, x="x", y="y", col="z", col_wrap=2)
g = self.plotfunc(d, x="x", y="y", col="z", col_wrap=2) # type: ignore[arg-type] # https://github.com/python/mypy/issues/15015
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This errors with

xarray/tests/test_plot.py:2045: error: Argument "col" has incompatible type "str"; expected "None"  [arg-type]

self.plotfunc is a staticmethod and it seems that mypy only chooses one of the overloads for that plotfunc.
Might be related to python/mypy#15015.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Well, nothing we can do about it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactoring the tests without the staticmethod trick was an idea I had, but I'm not in the mood for such a large rewrite.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Haha yes, I also thought about this several times already. Just too large of a refactor with almost no gains...

@Illviljan Illviljan added the plan to merge Final call for comments label Apr 15, 2023
@Illviljan Illviljan merged commit 6b7515c into pydata:main Apr 15, 2023
dcherian added a commit to dcherian/xarray that referenced this pull request Apr 18, 2023
* main: (34 commits)
  Update whats-new.rst
  Fix binning by unsorted array (pydata#7762)
  Bump codecov/codecov-action from 3.1.1 to 3.1.2 (pydata#7760)
  Fix typing errors using mypy 1.2 (pydata#7752)
  [skip-ci] dev whats-new
  Add whats-new for v2023.04.0 (pydata#7757)
  remove the `black` hook (pydata#7756)
  reword the what's new entry for the `pandas` 2.0 dtype changes (pydata#7755)
  restructure the contributing guide (pydata#7681)
  Continue to use nanosecond-precision Timestamps in precision-sensitive areas (pydata#7731)
  minor doc updates to clarify extensions using accessors (pydata#7751)
  align: Avoid reindexing when join="exact" (pydata#7736)
  `pandas=2.0` support (pydata#7724)
  Clarify vectorized indexing documentation (pydata#7747)
  Avoid recasting a CFTimeIndex (pydata#7735)
  fix typo (pydata#7746)
  [pre-commit.ci] pre-commit autoupdate (pydata#7745)
  Bump pypa/gh-action-pypi-publish from 1.8.4 to 1.8.5 (pydata#7743)
  preserve boolean dtype in encoding (pydata#7720)
  [skip-ci] Add alignment benchmarks (pydata#7738)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Automation Github bots, testing workflows, release automation plan to merge Final call for comments topic-combine combine/concat/merge topic-rolling topic-typing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

type checking CI is failing
2 participants