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
Don't type check __getattr__? #4601
Comments
Great observation @mathause . I think there are two parts of this:
Having methods like |
Good point. Given that the accessors are also going via |
Good point re accessors, I hadn't considered those. So sounds like raising an error on |
I think we can probably safely add Looking up coordinates with attributes like |
I can open a PR but is there a clean way to handle accessors? Do you prefer |
Has anyone tried this recently? For me mypy ignores the I think raising errors on not defined attributes is useful for typos but will likely annoy people that use custom accessors or use the variable shortcut (although the latter apparently don't care about type checking anyway). |
Figured it out: |
In #8204 I have noticed that defining |
In #4592 I had the issue that mypy did not raise an error on a missing method:
This is because
DataWithCoords
implements__getattr__
:The solution seems to be to not typecheck
__getattr__
(see python/mypy#6251 (comment)):The only
__getattr__
within xarray is here:xarray/xarray/core/common.py
Line 221 in 1735892
Using
@no_type_check
leads to 24 errors and not all of them can be trivially solved. E.g.DataWithCoords
wants of useself.isel
but does not implement the method. The solution is probably to addisel
toDataWithCoords
as anABC
or usingNotImplemented
.Thoughts?
All errors
Edit:
one problem is certainly the method injection, as mypy cannot detect those types.
The text was updated successfully, but these errors were encountered: