Skip to content

Commit 495226e

Browse files
committed
lint
1 parent 4fde588 commit 495226e

File tree

6 files changed

+25
-29
lines changed

6 files changed

+25
-29
lines changed

src/arviz_base/base.py

+15-15
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import importlib
44
import re
55
import warnings
6-
from collections.abc import Hashable, Iterable, Mapping
6+
from collections.abc import Callable, Hashable, Iterable, Mapping
77
from copy import deepcopy
8-
from typing import TYPE_CHECKING, Any, Callable, Optional, TypeVar, Union
8+
from typing import TYPE_CHECKING, Any, TypeVar
99

1010
import numpy as np
1111
import xarray as xr
@@ -24,9 +24,9 @@
2424
def generate_dims_coords(
2525
shape: Iterable[int],
2626
var_name: Hashable,
27-
dims: Optional[Iterable[Hashable]] = None,
28-
coords: Optional[CoordSpec] = None,
29-
index_origin: Optional[int] = None,
27+
dims: Iterable[Hashable] | None = None,
28+
coords: CoordSpec | None = None,
29+
index_origin: int | None = None,
3030
skip_event_dims: bool = False,
3131
check_conventions: bool = True,
3232
) -> tuple[list[Hashable], CoordSpec]:
@@ -216,12 +216,12 @@ def ndarray_to_dataarray(
216216
def dict_to_dataset(
217217
data: DictData,
218218
*,
219-
attrs: Optional[Mapping[Any, Any]] = None,
220-
inference_library: Optional[str] = None,
221-
coords: Optional[CoordSpec] = None,
222-
dims: Optional[DimSpec] = None,
223-
sample_dims: Optional[Iterable[Hashable]] = None,
224-
index_origin: Optional[int] = None,
219+
attrs: Mapping[Any, Any] | None = None,
220+
inference_library: str | None = None,
221+
coords: CoordSpec | None = None,
222+
dims: DimSpec | None = None,
223+
sample_dims: Iterable[Hashable] | None = None,
224+
index_origin: int | None = None,
225225
skip_event_dims: bool = False,
226226
check_conventions: bool = True,
227227
):
@@ -377,15 +377,15 @@ class requires: # pylint: disable=invalid-name
377377
See https://github.com/arviz-devs/arviz/pull/1504 for more discussion.
378378
"""
379379

380-
def __init__(self, *props: Union[str, list[str]]) -> None:
381-
self.props: tuple[Union[str, list[str]], ...] = props
380+
def __init__(self, *props: str | list[str]) -> None:
381+
self.props: tuple[str | list[str], ...] = props
382382

383383
def __call__(
384384
self, func: Callable[[RequiresArgTypeT], RequiresReturnTypeT]
385-
) -> Callable[[RequiresArgTypeT], Optional[RequiresReturnTypeT]]: # noqa: D202
385+
) -> Callable[[RequiresArgTypeT], RequiresReturnTypeT | None]: # noqa: D202
386386
"""Wrap the decorated function."""
387387

388-
def wrapped(cls: RequiresArgTypeT) -> Optional[RequiresReturnTypeT]:
388+
def wrapped(cls: RequiresArgTypeT) -> RequiresReturnTypeT | None:
389389
"""Return None if not all props are available."""
390390
for prop in self.props:
391391
prop_list = [prop] if isinstance(prop, str) else prop

src/arviz_base/io_dict.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Dictionary specific conversion code."""
22
import warnings
3-
from typing import Optional
43

54
from datatree import DataTree
65

@@ -14,7 +13,7 @@ def from_dict(
1413
name=None,
1514
sample_dims=None,
1615
save_warmup=None,
17-
index_origin: Optional[int] = None,
16+
index_origin: int | None = None,
1817
coords=None,
1918
dims=None,
2019
pred_dims=None,

src/arviz_base/labels.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# pylint: disable=unused-argument
22
"""Utilities to generate labels from xarray objects."""
3-
from typing import Union
43

54
__all__ = [
65
"mix_labellers",
@@ -92,7 +91,7 @@ def sel_to_str(self, sel: dict, isel: dict):
9291
)
9392
return ""
9493

95-
def var_name_to_str(self, var_name: Union[str, None]): # pylint: disable=no-self-use
94+
def var_name_to_str(self, var_name: str | None): # pylint: disable=no-self-use
9695
"""WIP."""
9796
return var_name
9897

@@ -106,7 +105,7 @@ def model_name_to_str(self, model_name): # pylint: disable=no-self-use
106105
"""WIP."""
107106
return model_name
108107

109-
def make_label_vert(self, var_name: Union[str, None], sel: dict, isel: dict):
108+
def make_label_vert(self, var_name: str | None, sel: dict, isel: dict):
110109
"""WIP."""
111110
var_name_str = self.var_name_to_str(var_name)
112111
sel_str = self.sel_to_str(sel, isel)

src/arviz_base/rcparams.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77
import sys
88
from collections.abc import MutableMapping
99
from pathlib import Path
10-
from typing import Any, Literal
10+
from typing import Any, Literal, get_args
1111

1212
import numpy as np
13-
from typing_extensions import get_args
1413

1514
_log = logging.getLogger("arviz")
1615

@@ -203,7 +202,7 @@ def validate_iterable(value):
203202
if allow_auto and value.lower() == "auto":
204203
return "auto"
205204
value = tuple(v.strip("([ ])") for v in value.split(",") if v.strip())
206-
if np.iterable(value) and not isinstance(value, (set, frozenset)):
205+
if np.iterable(value) and not isinstance(value, set | frozenset):
207206
val = tuple(scalar_validator(v) for v in value)
208207
if length is not None and len(val) != length:
209208
raise ValueError(f"Iterable must be of length: {length}")

src/arviz_base/testing.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
"""ArviZ testing utilities."""
22

3-
from typing import Union
43

54
from datatree import DataTree
65

76

87
def check_multiple_attrs(
98
test_dict: dict[str, list[str]], parent: DataTree
10-
) -> list[Union[str, tuple[str, str]]]:
9+
) -> list[str | tuple[str, str]]:
1110
"""Perform multiple hasattr checks on InferenceData objects.
1211
1312
It is thought to first check if the parent object contains a given dataset,
@@ -50,7 +49,7 @@ def check_multiple_attrs(
5049
in ``sample_stats``, also against what was expected.
5150
5251
"""
53-
failed_attrs: list[Union[str, tuple[str, str]]] = []
52+
failed_attrs: list[str | tuple[str, str]] = []
5453
for dataset_name, attributes in test_dict.items():
5554
if dataset_name.startswith("~"):
5655
if hasattr(parent, dataset_name[1:]):

src/arviz_base/utils.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def _var_names(var_names, data, filter_vars=None):
3232
)
3333

3434
if var_names is not None:
35-
if isinstance(data, (list, tuple)):
35+
if isinstance(data, list | tuple):
3636
all_vars = []
3737
for dataset in data:
3838
dataset_vars = list(dataset.data_vars)
@@ -156,7 +156,7 @@ def _get_coords(data, coords):
156156
data : Dataset or DataArray
157157
Return type is of the same type as the input
158158
"""
159-
if not isinstance(data, (list, tuple)):
159+
if not isinstance(data, list | tuple):
160160
try:
161161
return data.sel(**coords)
162162

@@ -170,7 +170,7 @@ def _get_coords(data, coords):
170170
"Check that coords structure is correct and"
171171
f" dimensions are valid. {err}"
172172
) from err
173-
if not isinstance(coords, (list, tuple)):
173+
if not isinstance(coords, list | tuple):
174174
coords = [coords] * len(data)
175175
data_subset = []
176176
for idx, (datum, coords_dict) in enumerate(zip(data, coords)):

0 commit comments

Comments
 (0)