From f5b293d0927506c2a979a091bf0d07ecc78fa181 Mon Sep 17 00:00:00 2001 From: Dmitrii Agibov Date: Thu, 8 Sep 2022 14:24:39 +0100 Subject: 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 --- src/mlia/cli/logging.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'src/mlia/cli/logging.py') diff --git a/src/mlia/cli/logging.py b/src/mlia/cli/logging.py index c5fc7bd..40f47d3 100644 --- a/src/mlia/cli/logging.py +++ b/src/mlia/cli/logging.py @@ -1,12 +1,11 @@ # SPDX-FileCopyrightText: Copyright 2022, Arm Limited and/or its affiliates. # SPDX-License-Identifier: Apache-2.0 """CLI logging configuration.""" +from __future__ import annotations + import logging import sys from pathlib import Path -from typing import List -from typing import Optional -from typing import Union from mlia.utils.logging import attach_handlers from mlia.utils.logging import create_log_handler @@ -18,7 +17,7 @@ _FILE_DEBUG_FORMAT = "%(asctime)s - %(name)s - %(levelname)s - %(message)s" def setup_logging( - logs_dir: Optional[Union[str, Path]] = None, + logs_dir: str | Path | None = None, verbose: bool = False, log_filename: str = "mlia.log", ) -> None: @@ -49,10 +48,10 @@ def setup_logging( def _get_mlia_handlers( - logs_dir: Optional[Union[str, Path]], + logs_dir: str | Path | None, log_filename: str, verbose: bool, -) -> List[logging.Handler]: +) -> list[logging.Handler]: """Get handlers for the MLIA loggers.""" result = [] stdout_handler = create_log_handler( @@ -84,10 +83,10 @@ def _get_mlia_handlers( def _get_tools_handlers( - logs_dir: Optional[Union[str, Path]], + logs_dir: str | Path | None, log_filename: str, verbose: bool, -) -> List[logging.Handler]: +) -> list[logging.Handler]: """Get handler for the tools loggers.""" result = [] if verbose: @@ -110,7 +109,7 @@ def _get_tools_handlers( return result -def _get_log_file(logs_dir: Union[str, Path], log_filename: str) -> Path: +def _get_log_file(logs_dir: str | Path, log_filename: str) -> Path: """Get the log file path.""" logs_dir_path = Path(logs_dir) logs_dir_path.mkdir(exist_ok=True) -- cgit v1.2.1