From 893c5ffcf546cfecc926d701741b76b0a5aa59b1 Mon Sep 17 00:00:00 2001 From: Scott Gasch Date: Mon, 8 May 2023 21:23:49 -0700 Subject: [PATCH] Improve type hints. --- src/pyutils/bootstrap.py | 3 ++- src/pyutils/config.py | 2 +- src/pyutils/decorator_utils.py | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/pyutils/bootstrap.py b/src/pyutils/bootstrap.py index f096add..7ef7ef1 100644 --- a/src/pyutils/bootstrap.py +++ b/src/pyutils/bootstrap.py @@ -45,6 +45,7 @@ import os import sys import uuid from inspect import stack +from typing import NoReturn from pyutils import config, logging_utils from pyutils.argparse_utils import ActionNoYes @@ -178,7 +179,7 @@ class ImportInterceptor(importlib.abc.MetaPathFinder): def should_ignore_filename(filename: str) -> bool: return "importlib" in filename or "six.py" in filename - def find_module(self, fullname, path): + def find_module(self, fullname, path) -> NoReturn: raise Exception( "This method has been deprecated since Python 3.4, please upgrade." ) diff --git a/src/pyutils/config.py b/src/pyutils/config.py index 9655f25..456be3e 100644 --- a/src/pyutils/config.py +++ b/src/pyutils/config.py @@ -410,7 +410,7 @@ class Config: """ return in_str.lower() in {"true", "1", "yes", "y", "t", "on"} - def _process_dynamic_args(self, event): + def _process_dynamic_args(self, event) -> None: """Invoked as a callback when a zk-based config changed.""" if not self.zk: diff --git a/src/pyutils/decorator_utils.py b/src/pyutils/decorator_utils.py index 1a429cf..f085697 100644 --- a/src/pyutils/decorator_utils.py +++ b/src/pyutils/decorator_utils.py @@ -18,7 +18,7 @@ import threading import time import traceback import warnings -from typing import Any, Callable, List, Optional, Union +from typing import Any, Callable, List, NoReturn, Optional, Union # This module is commonly used by others in here and should avoid # taking any unnecessary dependencies back on them. @@ -706,7 +706,7 @@ def thunkify(func): # to be bound by the terms and conditions of this License Agreement. -def _raise_exception(exception, error_message: Optional[str]): +def _raise_exception(exception, error_message: Optional[str]) -> NoReturn: """Internal. Raise a deferred exception""" if error_message is None: raise Exception(exception) -- 2.46.0