Skip to content

Commit a659b3e

Browse files
committed
Conditional typing
Signed-off-by: Cristian Le <cristian.le@mpsd.mpg.de>
1 parent 4836c6d commit a659b3e

1 file changed

Lines changed: 21 additions & 17 deletions

File tree

fmf/base.py

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,18 @@
1111
ValuesView)
1212
from io import open
1313
from pprint import pformat as pretty
14-
# TODO: py3.10: typing.Optional, typing.Union -> '|' operator
15-
from typing import Any, Optional, Union
14+
from typing import TYPE_CHECKING
1615

17-
from _typeshed import StrPath
16+
if TYPE_CHECKING:
17+
# TODO: py3.10: typing.Optional, typing.Union -> '|' operator
18+
from typing import Any, Optional, Union
1819

19-
if sys.version_info >= (3, 10):
20-
from typing import Self, TypeAlias
21-
else:
22-
from typing_extensions import TypeAlias, Self
20+
from _typeshed import StrPath
21+
22+
if sys.version_info >= (3, 10):
23+
from typing import Self, TypeAlias
24+
else:
25+
from typing_extensions import TypeAlias, Self
2326

2427
import jsonschema
2528
from ruamel.yaml import YAML
@@ -38,16 +41,17 @@
3841
MAIN = "main" + SUFFIX
3942
IGNORED_DIRECTORIES = ['/dev', '/proc', '/sys']
4043

41-
# TypeHints
42-
RawDataType: TypeAlias = Union[None, int, float, str, bool]
43-
ListDataType: TypeAlias = list[Union[RawDataType, 'ListDataType', 'DictDataType']]
44-
DictDataType: TypeAlias = dict[str, Union[RawDataType, ListDataType, 'DictDataType']]
45-
# Equivalent to:
46-
# JSON: TypeAlias = dict[str, "JSON"] | list["JSON"] | str | int | float | bool | None
47-
DataType: TypeAlias = Union[RawDataType, ListDataType, DictDataType]
48-
TreeData: TypeAlias = dict[str, DataType]
49-
TreeDataPath: TypeAlias = Union[TreeData, str] # Either TreeData or path
50-
JsonSchema: TypeAlias = Mapping[str, Any]
44+
if TYPE_CHECKING:
45+
# TypeHints
46+
RawDataType: TypeAlias = Union[None, int, float, str, bool]
47+
ListDataType: TypeAlias = list[Union[RawDataType, 'ListDataType', 'DictDataType']]
48+
DictDataType: TypeAlias = dict[str, Union[RawDataType, ListDataType, 'DictDataType']]
49+
# Equivalent to:
50+
# JSON: TypeAlias = dict[str, "JSON"] | list["JSON"] | str | int | float | bool | None
51+
DataType: TypeAlias = Union[RawDataType, ListDataType, DictDataType]
52+
TreeData: TypeAlias = dict[str, DataType]
53+
TreeDataPath: TypeAlias = Union[TreeData, str] # Either TreeData or path
54+
JsonSchema: TypeAlias = Mapping[str, Any]
5155

5256

5357
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)