issues: 748684119
This data as json
id | node_id | number | title | user | state | locked | assignee | milestone | comments | created_at | updated_at | closed_at | author_association | active_lock_reason | draft | pull_request | body | reactions | performed_via_github_app | state_reason | repo | type |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
748684119 | MDU6SXNzdWU3NDg2ODQxMTk= | 4601 | Don't type check __getattr__? | 10194086 | open | 0 | 8 | 2020-11-23T10:41:21Z | 2023-09-25T05:33:09Z | MEMBER | In #4592 I had the issue that mypy did not raise an error on a missing method: ```python from xarray.core.common import DataWithCoords hasattr(xr.core.common.DataWithCoords, "reduce") # -> False def test(x: "DataWithCoords"): x.reduce() # mypy does not error ``` This is because ```python class A: pass class B: def getattr(self, name): ... def testA(x: "A"): x.reduce() # mypy errors def testB(x: "B"): x.reduce() # mypy does not error ``` The solution seems to be to not typecheck ```python from typing import no_type_check class C: @no_type_check def getattr(self, name): ... def testC(x: "C"): x.reduce() # mypy errors ``` The only Using Thoughts? All errors
```python-traceback
xarray/core/common.py:370: error: "DataWithCoords" has no attribute "isel"
xarray/core/common.py:374: error: "DataWithCoords" has no attribute "dims"
xarray/core/common.py:378: error: "DataWithCoords" has no attribute "indexes"
xarray/core/common.py:381: error: "DataWithCoords" has no attribute "sizes"
xarray/core/common.py:698: error: "DataWithCoords" has no attribute "_groupby_cls"
xarray/core/common.py:761: error: "DataWithCoords" has no attribute "_groupby_cls"
xarray/core/common.py:866: error: "DataWithCoords" has no attribute "_rolling_cls"; maybe "_rolling_exp_cls"?
xarray/core/common.py:977: error: "DataWithCoords" has no attribute "_coarsen_cls"
xarray/core/common.py:1108: error: "DataWithCoords" has no attribute "dims"
xarray/core/common.py:1109: error: "DataWithCoords" has no attribute "dims"
xarray/core/common.py:1133: error: "DataWithCoords" has no attribute "indexes"
xarray/core/common.py:1144: error: "DataWithCoords" has no attribute "_resample_cls"; maybe "resample"?
xarray/core/common.py:1261: error: "DataWithCoords" has no attribute "isel"
xarray/core/alignment.py:278: error: "DataAlignable" has no attribute "copy"
xarray/core/alignment.py:283: error: "DataAlignable" has no attribute "dims"
xarray/core/alignment.py:286: error: "DataAlignable" has no attribute "indexes"
xarray/core/alignment.py:288: error: "DataAlignable" has no attribute "sizes"
xarray/core/alignment.py:348: error: "DataAlignable" has no attribute "dims"
xarray/core/alignment.py:351: error: "DataAlignable" has no attribute "copy"
xarray/core/alignment.py:353: error: "DataAlignable" has no attribute "reindex"
xarray/core/alignment.py:356: error: "DataAlignable" has no attribute "encoding"
xarray/core/weighted.py:157: error: "DataArray" has no attribute "notnull"
xarray/core/dataset.py:3792: error: "Dataset" has no attribute "virtual_variables"
xarray/core/dataset.py:6135: error: "DataArray" has no attribute "isnull"
```
Edit: one problem is certainly the method injection, as mypy cannot detect those types. |
{ "url": "https://api.github.com/repos/pydata/xarray/issues/4601/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
13221727 | issue |