Repository navigation
Description
What is your issue?
Pyright is a full-featured, standards-based static type checker for Python, recently I tried it with xarray and get an error.
And mypy generates the same error.
So I wonder if we can fix this error, although this error won't have any impacts except for static type checker errors.
I have been using xarray for several years and recently began using Pyright. However, I encountered the following error:
Argument missing for parameter 'self'Although my code still executes normally, I am curious about the cause of this error. Is this behavior expected?import xarray as xr import matplotlib.pyplot as plt data = xr.DataArray([1, 2, 3], dims=['x']) fig, ax= plt.subplots(ncols=1, nrows=1) data.plot(ax=ax)It seems to related to the codes here:
plot = utils.UncachedAccessor(DataArrayPlotAccessor)class UncachedAccessor(Generic[_Accessor]): """Acts like a property, but on both classes and class instances This class is necessary because some tools (e.g. pydoc and sphinx) inspect classes for which property returns itself and not the accessor. """ def __init__(self, accessor: type[_Accessor]) -> None: self._accessor = accessor @overload def __get__(self, obj: None, cls) -> type[_Accessor]: ... @overload def __get__(self, obj: object, cls) -> _Accessor: ... def __get__(self, obj: None | object, cls) -> type[_Accessor] | _Accessor: if obj is None: return self._accessor return self._accessor(obj) # type: ignore # assume it is a valid accessor!
Here is my
xarrayversion:xarray 2023.2.0 pyhd8ed1ab_0 conda-forge
Originally posted by @singledoggy in #9150
Pyright is behaving correctly here. Not surprisingly, mypy generates the same error.
The problem appears to be in the
xarraylibrary here:class DataArrayPlotAccessor: ... @functools.wraps(dataarray_plot.plot, assigned=("__doc__", "__annotations__")) def __call__(self, **kwargs) -> Any: return dataarray_plot.plot(self._da, **kwargs)Originally posted by @erictraut in microsoft/pyright#8203 (comment)
Activity
welcome commentedon Jun 23, 2024
Thanks for opening your first issue here at xarray! Be sure to follow the issue template!
If you have an idea for a solution, we would really welcome a Pull Request with proposed changes.
See the Contributing Guide for more.
It may take us a while to respond here, but we really value your contribution. Contributors like you help make xarray better.
Thank you!
max-sixty commentedon Jun 23, 2024
Is the error still present on a recent version of xarray?
singledoggy commentedon Jun 24, 2024
Before, I only read through the latest code and didn't find any relevant changes. I just had time to test the latest version, but the issue still persists.
max-sixty commentedon Jun 24, 2024
OK. Mypy does pass — so if you find a mypy error in the current version then that's news, we'd like to understand that.
We do have a pyright job in CI, but it doesn't pass and so the check is allowed to fail. We're definitely open to contributions that improve it, and probably we'd be happy to turn on the check if we could get everything to pass.
Though it's not feasible to have an open issue for every pyright error so we can close this unless there's more info; hope that's reasonable.
singledoggy commentedon Jun 24, 2024
mypy also get this error
As @erictraut points out here, mypy wil generate the same error.
I also tested it with command:
mypy test.pywith the latest version (v2024.06.0) by myself.It's reasonable if you choose to close this issue.
Version information
Add test for pydata#9155
max-sixty commentedon Jun 24, 2024
Thanks for the example and mypy output.
I see now — it's that our mypy version in CI is a bit out of date, and it does indeed raise an error with the newer mypy 1.10.0. Thanks for helping debug it.
I'll adjust the title of the issue if that's OK
[-]pyright error Argument missing for parameter "self" when plot[/-][+]mypy 1.10.0 fails with matplotlib wrappers[/+]max-sixty commentedon Jun 24, 2024
I (edit: can't) immediately see what's going on, so I'll have to leave it for the moment. (If anyone wants to dive in, that would be great).
Thanks for finding it @singledoggy
Add test for #9155 (#9161)
headtr1ck commentedon Jun 24, 2024
Just ran into the same problem. Also when running mypy on xarray codebase (-> 70 errors)
headtr1ck commentedon Jun 24, 2024
Looks like python/mypy#17166
Merge branch 'main' into grouper-public-api
Merge branch 'main' into backend-indexing
max-sixty commentedon Oct 18, 2024
I think this is mostly covered now — we have ignores, we can wait for the mypy upstream issue before removing.
Merge branch 'main' into backend-indexing