Skip to content

Commit d83eb59

Browse files
committed
typing: use pipe to denote unions
1 parent e6acc68 commit d83eb59

File tree

4 files changed

+18
-27
lines changed

4 files changed

+18
-27
lines changed

src/stagpy/commands.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from .stagyydata import _sdat_from_conf
1616

1717
if typing.TYPE_CHECKING:
18-
from typing import Callable, Iterable, Mapping, Sequence, Union
18+
from typing import Callable, Iterable, Mapping, Sequence
1919

2020
from loam.base import Section
2121

@@ -100,7 +100,7 @@ def _pretty_print(
100100

101101

102102
def _layout(
103-
dict_vars: Mapping[str, Union[Varf, Varr, Vart]],
103+
dict_vars: Mapping[str, Varf | Varr | Vart],
104104
dict_vars_extra: Mapping[str, Callable],
105105
) -> None:
106106
"""Print nicely [(var, description)] from phyvars."""

src/stagpy/config.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from dataclasses import dataclass
1010
from pathlib import Path
11-
from typing import Dict, Sequence, Union
11+
from typing import Dict, Sequence
1212

1313
import loam.parsers as lprs
1414
from loam.base import ConfigBase, Section, entry
@@ -41,10 +41,10 @@ class Core(Section):
4141
read_parameters_dat: bool = switch_opt(True, None, "enable reading parameters.dat")
4242
outname: str = entry(val="stagpy", cli_short="n", doc="output file name prefix")
4343
shortname: bool = switch_opt(False, None, "output file name is only prefix")
44-
timesteps: Sequence[Union[int, slice]] = _indices.entry(
44+
timesteps: Sequence[int | slice] = _indices.entry(
4545
doc="timesteps slice", in_file=False, cli_short="t"
4646
)
47-
snapshots: Sequence[Union[int, slice]] = _indices.entry(
47+
snapshots: Sequence[int | slice] = _indices.entry(
4848
default=[-1], doc="snapshots slice", in_file=False, cli_short="s"
4949
)
5050

@@ -159,10 +159,10 @@ class Time(Section):
159159
marktimes: Sequence[float] = TupleEntry(float).entry(
160160
doc="list of times where to put a mark", in_file=False, cli_short="M"
161161
)
162-
marksteps: Sequence[Union[int, slice]] = _indices.entry(
162+
marksteps: Sequence[int | slice] = _indices.entry(
163163
doc="list of steps where to put a mark", in_file=False, cli_short="T"
164164
)
165-
marksnaps: Sequence[Union[int, slice]] = _indices.entry(
165+
marksnaps: Sequence[int | slice] = _indices.entry(
166166
doc="list of snaps where to put a mark", in_file=False, cli_short="S"
167167
)
168168

src/stagpy/plates.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from .stagyydata import _sdat_from_conf
1919

2020
if typing.TYPE_CHECKING:
21-
from typing import Sequence, TextIO, Union
21+
from typing import Sequence, TextIO
2222

2323
from matplotlib.axes import Axes
2424
from numpy.typing import NDArray
@@ -188,7 +188,7 @@ def _continents_location(snap: Step, at_surface: bool = True) -> NDArray:
188188
If at_surface is True, it is evaluated only at the surface, otherwise it is
189189
evaluated in the entire domain.
190190
"""
191-
icont: Union[int, slice]
191+
icont: int | slice
192192
if at_surface:
193193
if snap.sdat.par.get("boundaries", "air_layer", False):
194194
icont = _isurf(snap) - 6

src/stagpy/stagyydata.py

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,14 @@
2626

2727
if typing.TYPE_CHECKING:
2828
from os import PathLike
29-
from typing import (
30-
Any,
31-
Callable,
32-
Iterable,
33-
Iterator,
34-
Sequence,
35-
Union,
36-
)
29+
from typing import Any, Callable, Iterable, Iterator, Sequence, TypeAlias
3730

3831
from numpy.typing import NDArray
3932
from pandas import DataFrame, Series
4033

4134
from .config import Core
4235

43-
StepIndex = Union[int, slice]
36+
StepIndex: TypeAlias = int | slice
4437

4538

4639
@typing.overload
@@ -56,8 +49,8 @@ def _as_view_item(obj: int) -> None: ...
5649

5750

5851
def _as_view_item(
59-
obj: Union[Sequence[StepIndex], slice, int],
60-
) -> Union[Sequence[StepIndex], Sequence[slice], None]:
52+
obj: Sequence[StepIndex] | slice | int,
53+
) -> Sequence[StepIndex] | Sequence[slice] | None:
6154
"""Return None or a suitable iterable to build a StepsView."""
6255
try:
6356
iter(obj) # type: ignore
@@ -312,11 +305,9 @@ def __repr__(self) -> str:
312305
def __getitem__(self, istep: int) -> Step: ...
313306

314307
@typing.overload
315-
def __getitem__(self, istep: Union[slice, Sequence[StepIndex]]) -> StepsView: ...
308+
def __getitem__(self, istep: slice | Sequence[StepIndex]) -> StepsView: ...
316309

317-
def __getitem__(
318-
self, istep: Union[int, slice, Sequence[StepIndex]]
319-
) -> Union[Step, StepsView]:
310+
def __getitem__(self, istep: int | slice | Sequence[StepIndex]) -> Step | StepsView:
320311
keys = _as_view_item(istep)
321312
if keys is not None:
322313
return StepsView(self, keys)
@@ -406,9 +397,9 @@ def __repr__(self) -> str:
406397
def __getitem__(self, istep: int) -> Step: ...
407398

408399
@typing.overload
409-
def __getitem__(self, istep: Union[slice, Sequence[StepIndex]]) -> StepsView: ...
400+
def __getitem__(self, istep: slice | Sequence[StepIndex]) -> StepsView: ...
410401

411-
def __getitem__(self, isnap: Any) -> Union[Step, StepsView]:
402+
def __getitem__(self, isnap: Any) -> Step | StepsView:
412403
keys = _as_view_item(isnap)
413404
if keys is not None:
414405
return StepsView(self, keys).filter(snap=True)
@@ -545,7 +536,7 @@ class StepsView:
545536
items: iterable of isteps/isnaps or slices.
546537
"""
547538

548-
def __init__(self, steps_col: Union[Steps, Snaps], items: Sequence[StepIndex]):
539+
def __init__(self, steps_col: Steps | Snaps, items: Sequence[StepIndex]):
549540
self._col = steps_col
550541
self._items = items
551542
self._rprofs_averaged: RprofsAveraged | None = None

0 commit comments

Comments
 (0)