Skip to content

Commit 74fdb9e

Browse files
committed
fix pyright partially
1 parent 40a367c commit 74fdb9e

File tree

6 files changed

+883
-780
lines changed

6 files changed

+883
-780
lines changed

pixi.lock

Lines changed: 856 additions & 749 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,13 @@ tests = "pytest"
7676
doc_build = { cmd = "sphinx-apidoc -efT -o docs/_apidoc src/xarray_dataclasses && sphinx-build -a docs docs/_build" }
7777

7878
[tool.pyright]
79-
reportImportCycles = "warning"
80-
reportUnknownArgumentType = "warning"
81-
reportUnknownMemberType = "warning"
82-
reportUnknownVariableType = "warning"
79+
reportMissingImports = "none"
80+
reportImportCycles = "none"
81+
reportUnknownArgumentType = "none"
82+
reportUnknownMemberType = "none"
83+
reportUnknownVariableType = "none"
84+
reportUnknownParameterType = "none"
85+
reportUntypedFunctionDecorator = "none"
8386
typeCheckingMode = "strict"
8487

8588
[tool.pixi.pypi-dependencies]

src/xarray_dataclasses/datamodel.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from typing import (
99
Any,
1010
Dict,
11+
get_type_hints,
1112
Hashable,
1213
List,
1314
Literal,
@@ -22,7 +23,7 @@
2223
# dependencies
2324
import numpy as np
2425
import xarray as xr
25-
from typing_extensions import ParamSpec, get_type_hints
26+
from typing_extensions import ParamSpec
2627

2728

2829
# submodules
@@ -133,7 +134,7 @@ def __post_init__(self) -> None:
133134
if model.names:
134135
setattr(self, "name", model.names[0].value)
135136

136-
def __call__(self, reference: Optional[AnyXarray] = None) -> xr.DataArray:
137+
def __call__(self, reference: Optional[AnyXarray] = None) -> xr.DataArray: # pyright: ignore[reportUnknownParameterType]
137138
"""Create a DataArray object according to the entry."""
138139
from .dataarray import asdataarray
139140

@@ -250,11 +251,11 @@ def get_entry(field: AnyField, value: Any) -> Optional[AnyEntry]:
250251
)
251252

252253

253-
def get_typedarray(
254+
def get_typedarray( # pyright: ignore[reportUnknownParameterType]
254255
data: Any,
255256
dims: Dims,
256-
dtype: Optional[AnyDType],
257-
reference: Optional[AnyXarray] = None,
257+
dtype: Optional[AnyDType], # pyright: ignore[reportUnknownParameterType]
258+
reference: Optional[AnyXarray] = None, # pyright: ignore[reportUnknownParameterType]
258259
) -> xr.DataArray:
259260
"""Create a DataArray object with given dims and dtype.
260261

src/xarray_dataclasses/typing.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,15 @@
2323
from enum import Enum
2424
from itertools import chain
2525
from typing import (
26+
Annotated,
2627
Any,
2728
ClassVar,
2829
Collection,
2930
Dict,
3031
Generic,
32+
get_args,
33+
get_origin,
34+
get_type_hints,
3135
Hashable,
3236
Iterable,
3337
Literal,
@@ -44,14 +48,7 @@
4448
# dependencies
4549
import numpy as np
4650
import xarray as xr
47-
from typing_extensions import (
48-
Annotated,
49-
ParamSpec,
50-
TypeAlias,
51-
get_args,
52-
get_origin,
53-
get_type_hints,
54-
)
51+
from typing_extensions import ParamSpec, TypeAlias
5552

5653

5754
# type hints (private)
@@ -62,10 +59,10 @@
6259
TDType = TypeVar("TDType", covariant=True)
6360
THashable = TypeVar("THashable", bound=Hashable)
6461

65-
AnyArray: TypeAlias = "np.ndarray[Any, Any]"
66-
AnyDType: TypeAlias = "np.dtype[Any]"
67-
AnyField: TypeAlias = "Field[Any]"
68-
AnyXarray: TypeAlias = "xr.DataArray | xr.Dataset"
62+
AnyArray: TypeAlias = np.ndarray
63+
AnyDType: TypeAlias = np.dtype
64+
AnyField: TypeAlias = Field[Any]
65+
AnyXarray: TypeAlias = Union[xr.DataArray, xr.Dataset]
6966
Dims = Tuple[str, ...]
7067
Order = Literal["C", "F"]
7168
Shape = Union[Sequence[int], int]
@@ -325,7 +322,7 @@ def get_dims(tp: Any) -> Dims:
325322
return tuple(str(get_args(arg)[0]) for arg in args)
326323

327324

328-
def get_dtype(tp: Any) -> Optional[AnyDType]:
325+
def get_dtype(tp: Any) -> Optional[AnyDType]: # pyright: ignore[reportUnknownParameterType]
329326
"""Extract a NumPy data type (dtype)."""
330327
try:
331328
dtype = get_args(get_args(get_annotated(tp))[1])[0]

tests/test_dataarray.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
from dataclasses import dataclass
33
from typing import Literal, Tuple
44

5-
65
# dependencies
76
import numpy as np
87
import xarray as xr
8+
from typing_extensions import TypeAlias
99

1010

1111
# submodules
@@ -24,11 +24,7 @@
2424
Y = Literal["y"]
2525

2626

27-
# dataclasses
28-
class Custom(xr.DataArray):
29-
"""Custom DataArray."""
30-
31-
__slots__ = ()
27+
Custom: TypeAlias = xr.DataArray
3228

3329

3430
@dataclass

tests/test_dataset.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# dependencies
77
import numpy as np
88
import xarray as xr
9+
from typing_extensions import TypeAlias
910

1011

1112
# submodules
@@ -24,9 +25,7 @@
2425
Y = Literal["y"]
2526

2627

27-
# dataclasses
28-
class Custom(xr.Dataset):
29-
__slots__ = ()
28+
Custom: TypeAlias = xr.Dataset
3029

3130

3231
@dataclass

0 commit comments

Comments
 (0)