Skip to content

Commit f448dc0

Browse files
authored
#153 Merge pull request from astropenguin/astropenguin/issue152
Update static type check
2 parents 130db6c + 7502f51 commit f448dc0

File tree

12 files changed

+126
-110
lines changed

12 files changed

+126
-110
lines changed

.devcontainer/devcontainer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
"settings": {
1616
"files.insertFinalNewline": true,
1717
"files.trimTrailingWhitespace": true,
18-
"python.analysis.typeCheckingMode": "strict",
1918
"python.formatting.provider": "black",
2019
"python.languageServer": "Pylance",
2120
"[python]": {

.github/workflows/tests.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,20 @@ jobs:
1515
env:
1616
POETRY_VIRTUALENVS_CREATE: false
1717
strategy:
18+
fail-fast: false
1819
matrix:
1920
python: ["3.7", "3.8", "3.9", "3.10"]
2021
steps:
2122
- uses: actions/checkout@v2
2223
- uses: actions/setup-python@v2
2324
with:
2425
python-version: ${{ matrix.python }}
25-
- uses: actions/setup-node@v2
26-
with:
27-
node-version: "lts/gallium"
2826
- name: Install project dependencies
29-
run: pip install poetry && poetry install && npm install
27+
run: pip install poetry && poetry install
3028
- name: Test code's formatting (Black)
3129
run: black --check docs tests xarray_dataclasses
3230
- name: Test code's typing (Pyright)
33-
run: npx pyright docs tests xarray_dataclasses
31+
run: pyright docs tests xarray_dataclasses
3432
- name: Test code's execution (pytest)
3533
run: pytest -v tests
3634
- name: Test docs' building (Sphinx)

package-lock.json

Lines changed: 0 additions & 33 deletions
This file was deleted.

package.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

poetry.lock

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

pyproject.toml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ documentation = "https://astropenguin.github.io/xarray-dataclasses/"
1313
python = ">=3.7.1, <3.11"
1414
morecopy = "^0.2"
1515
more-itertools = "^8.12"
16-
numpy = "^1.15"
16+
numpy = [
17+
{ version = ">=1.15, <1.22", python = ">=3.7.1, <3.8" },
18+
{ version = "^1.15", python = ">=3.8, <3.11" },
19+
]
1720
typing-extensions = "^3.10"
1821
xarray = [
1922
{ version = ">=0.18, <0.21", python = ">=3.7.1, <3.8" },
@@ -28,9 +31,17 @@ ipython = [
2831
]
2932
myst-parser = "^0.17"
3033
pydata-sphinx-theme = "^0.8"
34+
pyright = "^1.1"
3135
pytest = "^7.1"
3236
sphinx = "^4.5"
3337

38+
[tool.pyright]
39+
reportImportCycles = "warning"
40+
reportUnknownArgumentType = "warning"
41+
reportUnknownMemberType = "warning"
42+
reportUnknownVariableType = "warning"
43+
typeCheckingMode = "strict"
44+
3445
[build-system]
3546
requires = ["poetry-core>=1.0.0"]
3647
build-backend = "poetry.core.masonry.api"

pyrightconfig.json

Lines changed: 0 additions & 8 deletions
This file was deleted.

xarray_dataclasses/__init__.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,6 @@
22
__version__ = "1.1.0"
33

44

5-
# for Python 3.7 and 3.8
6-
def _make_field_generic():
7-
from dataclasses import Field
8-
from typing import Sequence
9-
10-
GenericAlias = type(Sequence[int])
11-
Field.__class_getitem__ = classmethod(GenericAlias)
12-
13-
14-
_make_field_generic()
15-
16-
175
# submodules
186
from . import dataarray
197
from . import dataset

xarray_dataclasses/dataarray.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
# submodules
2828
from .datamodel import DataModel
2929
from .dataoptions import DataOptions
30-
from .typing import DataClass, DataClassFields, DataType, Order, Shape, Sizes
30+
from .typing import AnyArray, DataClass, DataClassFields, DataType, Order, Shape, Sizes
3131

3232

3333
# type hints
@@ -168,7 +168,7 @@ def new(cls: Any, *args: Any, **kwargs: Any) -> Any:
168168
@classmethod
169169
def shaped(
170170
cls: Type[OptionedClass[PInit, TDataArray]],
171-
func: Callable[[Shape], np.ndarray],
171+
func: Callable[[Shape], AnyArray],
172172
shape: Union[Shape, Sizes],
173173
**kwargs: Any,
174174
) -> TDataArray:
@@ -178,7 +178,7 @@ def shaped(
178178
@classmethod
179179
def shaped(
180180
cls: Type[DataClass[PInit]],
181-
func: Callable[[Shape], np.ndarray],
181+
func: Callable[[Shape], AnyArray],
182182
shape: Union[Shape, Sizes],
183183
**kwargs: Any,
184184
) -> xr.DataArray:
@@ -187,7 +187,7 @@ def shaped(
187187
@classmethod
188188
def shaped(
189189
cls: Any,
190-
func: Callable[[Shape], np.ndarray],
190+
func: Callable[[Shape], AnyArray],
191191
shape: Union[Shape, Sizes],
192192
**kwargs: Any,
193193
) -> Any:

xarray_dataclasses/datamodel.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44

55
# standard library
6-
from dataclasses import Field, dataclass, field, is_dataclass
6+
from dataclasses import dataclass, field, is_dataclass
77
from typing import Any, Dict, Hashable, List, Optional, Tuple, Type, Union, cast
88

99

@@ -15,6 +15,7 @@
1515

1616
# submodules
1717
from .typing import (
18+
AnyField,
1819
DataClass,
1920
DataType,
2021
Dims,
@@ -204,7 +205,7 @@ def eval_dataclass(dataclass: AnyDataClass[PInit]) -> None:
204205
field.type = types[field.name]
205206

206207

207-
def get_entry(field: Field[Any], value: Any) -> AnyEntry:
208+
def get_entry(field: AnyField, value: Any) -> AnyEntry:
208209
"""Create an entry from a field and its value."""
209210
field_type = get_field_type(field.type)
210211
repr_type = get_repr_type(field.type)

0 commit comments

Comments
 (0)