|
3 | 3 | from collections.abc import Iterable, Mapping, Sequence |
4 | 4 | from functools import lru_cache |
5 | 5 | from itertools import chain, product, zip_longest |
6 | | -from typing import Optional, TypeVar, Union |
| 6 | +from typing import TypeVar |
7 | 7 | from warnings import warn |
8 | 8 |
|
9 | 9 | import ixmp |
@@ -255,12 +255,15 @@ def cat(self, name, cat): |
255 | 255 | def add_par( |
256 | 256 | self, |
257 | 257 | name: str, |
258 | | - key_or_data: Optional[ |
259 | | - Union[int, str, Sequence[Union[int, str]], dict, pd.DataFrame] |
260 | | - ] = None, |
261 | | - value: Union[float, Iterable[float], None] = None, |
262 | | - unit: Union[str, Iterable[str], None] = None, |
263 | | - comment: Union[str, Iterable[str], None] = None, |
| 258 | + key_or_data: int |
| 259 | + | str |
| 260 | + | Sequence[int | str] |
| 261 | + | dict |
| 262 | + | pd.DataFrame |
| 263 | + | None = None, |
| 264 | + value: float | Iterable[float] | None = None, |
| 265 | + unit: str | Iterable[str] | None = None, |
| 266 | + comment: str | Iterable[str] | None = None, |
264 | 267 | ) -> None: |
265 | 268 | # ixmp.Scenario.add_par() is typed as accepting only str, but this method also |
266 | 269 | # accepts int for "year"-like dimensions. Proxy the call to avoid type check |
@@ -295,14 +298,12 @@ def add_par( |
295 | 298 | def add_set( |
296 | 299 | self, |
297 | 300 | name: str, |
298 | | - key: Union[ |
299 | | - int, |
300 | | - str, |
301 | | - Iterable[object], |
302 | | - dict[str, Union[Sequence[int], Sequence[str]]], |
303 | | - pd.DataFrame, |
304 | | - ], |
305 | | - comment: Union[str, Sequence[str], None] = None, |
| 301 | + key: int |
| 302 | + | str |
| 303 | + | Iterable[object] |
| 304 | + | dict[str, Sequence[int] | Sequence[str]] |
| 305 | + | pd.DataFrame, |
| 306 | + comment: str | Sequence[str] | None = None, |
306 | 307 | ) -> None: |
307 | 308 | # ixmp.Scenario.add_par() is typed as accepting only str, but this method also |
308 | 309 | # accepts int for "year"-like dimensions. Proxy the call to avoid type check |
@@ -373,8 +374,8 @@ def recurse(k, v, parent="World"): |
373 | 374 | def add_horizon( |
374 | 375 | self, |
375 | 376 | year: Iterable[int] = [], |
376 | | - firstmodelyear: Optional[int] = None, |
377 | | - data: Optional[dict] = None, |
| 377 | + firstmodelyear: int | None = None, |
| 378 | + data: dict | None = None, |
378 | 379 | ) -> None: |
379 | 380 | """Set the scenario time horizon via ``year`` and related categories. |
380 | 381 |
|
@@ -502,7 +503,7 @@ def add_horizon( |
502 | 503 |
|
503 | 504 | def vintage_and_active_years( |
504 | 505 | self, |
505 | | - ya_args: Union[tuple[str, str], tuple[str, str, Union[int, str]], None] = None, |
| 506 | + ya_args: tuple[str, str] | tuple[str, str, int | str] | None = None, |
506 | 507 | tl_only: bool = True, |
507 | 508 | **kwargs, |
508 | 509 | ) -> pd.DataFrame: |
@@ -653,7 +654,7 @@ def _valid(elem): |
653 | 654 | #: Alias for :meth:`vintage_and_active_years`. |
654 | 655 | yv_ya = vintage_and_active_years |
655 | 656 |
|
656 | | - def years_active(self, node: str, tec: str, yr_vtg: Union[int, str]) -> list[int]: |
| 657 | + def years_active(self, node: str, tec: str, yr_vtg: int | str) -> list[int]: |
657 | 658 | """Return periods in which `tec` hnology of `yr_vtg` can be active in `node`. |
658 | 659 |
|
659 | 660 | The :ref:`parameters <params-tech>` ``duration_period`` and |
@@ -762,7 +763,7 @@ def solve(self, model="MESSAGE", solve_options={}, **kwargs): |
762 | 763 |
|
763 | 764 | def add_macro( |
764 | 765 | self, |
765 | | - data: Union[Mapping, os.PathLike], |
| 766 | + data: Mapping | os.PathLike, |
766 | 767 | scenario=None, |
767 | 768 | check_convergence=True, |
768 | 769 | **kwargs, |
|
0 commit comments