From 49d12c1b79d737f0b73d308bba40628db960a97a Mon Sep 17 00:00:00 2001 From: Andrew Grimberg Date: Fri, 6 Oct 2023 14:52:27 -0700 Subject: [PATCH] Refactor: Add annotations to base lftools Issue: RELENG-4933 Signed-off-by: Andrew Grimberg Change-Id: I9d793ebe4db3ca47dafee56c9016789f8bcd3f1f --- lftools/__init__.py | 12 +++++++----- mypy.ini | 24 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 mypy.ini diff --git a/lftools/__init__.py b/lftools/__init__.py index fa8c8d36..e954bdc2 100644 --- a/lftools/__init__.py +++ b/lftools/__init__.py @@ -1,6 +1,6 @@ # SPDX-License-Identifier: EPL-1.0 ############################################################################## -# Copyright (c) 2017 The Linux Foundation and others. +# Copyright (c) 2017, 2023 The Linux Foundation and others. # # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Public License v1.0 @@ -9,8 +9,10 @@ # # Contributors: # Thanh Ha - Initial implementation +# Linux Foundation Release Engineering ############################################################################## """lftools package.""" +from __future__ import annotations __author__ = "Thanh Ha" __summary__ = "Linux Foundation Release Engineering Tools" @@ -22,11 +24,11 @@ import sys class LogFormatter(logging.Formatter): """Custom log formatter.""" - default_fmt = logging.Formatter("%(levelname)s: %(message)s") - debug_fmt = logging.Formatter("%(levelname)s: %(name)s:%(lineno)d: %(message)s") - info_fmt = logging.Formatter("%(message)s") + default_fmt: logging.Formatter = logging.Formatter("%(levelname)s: %(message)s") + debug_fmt: logging.Formatter = logging.Formatter("%(levelname)s: %(name)s:%(lineno)d: %(message)s") + info_fmt: logging.Formatter = logging.Formatter("%(message)s") - def format(self, record): + def format(self, record: logging.LogRecord) -> str: """Format log messages depending on log level.""" if record.levelno == logging.INFO: return self.info_fmt.format(record) diff --git a/mypy.ini b/mypy.ini new file mode 100644 index 00000000..8c8efb4b --- /dev/null +++ b/mypy.ini @@ -0,0 +1,24 @@ +[mypy] +warn_return_any = True +warn_unused_configs = True + +[mypy-defusedxml.minidom.*] +ignore_missing_imports = True + +[mypy-docker.*] +ignore_missing_imports = True + +[mypy-jenkins.*] +ignore_missing_imports = True + +[mypy-ldap.*] +ignore_missing_imports = True + +[mypy-oauth2client.*] +ignore_missing_imports = True + +[mypy-pygerrit2.*] +ignore_missing_imports = True + +[mypy-ruamel.*] +ignore_missing_imports = True -- 2.16.6