diff options
author | Dmitrii Agibov <dmitrii.agibov@arm.com> | 2022-09-08 14:24:39 +0100 |
---|---|---|
committer | Dmitrii Agibov <dmitrii.agibov@arm.com> | 2022-09-09 17:21:48 +0100 |
commit | f5b293d0927506c2a979a091bf0d07ecc78fa181 (patch) | |
tree | 4de585b7cb6ed34da8237063752270189a730a41 /src/mlia/utils/types.py | |
parent | cde0c6ee140bd108849bff40467d8f18ffc332ef (diff) | |
download | mlia-f5b293d0927506c2a979a091bf0d07ecc78fa181.tar.gz |
MLIA-386 Simplify typing in the source code
- Enable deferred annotations evaluation
- Use builtin types for type hints whenever possible
- Use | syntax for union types
- Rename mlia.core._typing into mlia.core.typing
Change-Id: I3f6ffc02fa069c589bdd9e8bddbccd504285427a
Diffstat (limited to 'src/mlia/utils/types.py')
-rw-r--r-- | src/mlia/utils/types.py | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/mlia/utils/types.py b/src/mlia/utils/types.py index 9b63928..ea067b8 100644 --- a/src/mlia/utils/types.py +++ b/src/mlia/utils/types.py @@ -1,11 +1,12 @@ # SPDX-FileCopyrightText: Copyright 2022, Arm Limited and/or its affiliates. # SPDX-License-Identifier: Apache-2.0 """Types related utility functions.""" +from __future__ import annotations + from typing import Any -from typing import Optional -def is_list_of(data: Any, cls: type, elem_num: Optional[int] = None) -> bool: +def is_list_of(data: Any, cls: type, elem_num: int | None = None) -> bool: """Check if data is a list of object of the same class.""" return ( isinstance(data, (tuple, list)) @@ -24,7 +25,7 @@ def is_number(value: str) -> bool: return True -def parse_int(value: Any, default: Optional[int] = None) -> Optional[int]: +def parse_int(value: Any, default: int | None = None) -> int | None: """Parse integer value.""" try: return int(value) |