Skip to content

Commit

Permalink
Fix type annotations of logging.run_main and .run_cli
Browse files Browse the repository at this point in the history
  • Loading branch information
opcode81 committed Jul 11, 2024
1 parent d0711a3 commit 9cf3c32
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## Unreleased

### Improvements/Changes

* `util.logging`:
* Fix type annotations of `run_main` and `run_cli`

## v1.2.0 (2024-06-10)

### Improvements/Changes
Expand Down
7 changes: 4 additions & 3 deletions src/sensai/util/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
from datetime import datetime
from io import StringIO
from logging import *
from typing import List, Callable, Any, Optional
from typing import List, Callable, Any, Optional, TypeVar

import pandas as pd

log = getLogger(__name__)

LOG_DEFAULT_FORMAT = '%(levelname)-5s %(asctime)-15s %(name)s:%(funcName)s:%(lineno)d - %(message)s'
T = TypeVar("T")

# Holds the log format that is configured by the user (using function `configure`), such
# that it can be reused in other places
Expand Down Expand Up @@ -82,7 +83,7 @@ def configure(format=LOG_DEFAULT_FORMAT, level=lg.DEBUG):


# noinspection PyShadowingBuiltins
def run_main(main_fn: Callable[[], Any], format=LOG_DEFAULT_FORMAT, level=lg.DEBUG):
def run_main(main_fn: Callable[..., T], format=LOG_DEFAULT_FORMAT, level=lg.DEBUG) -> T:
"""
Configures logging with the given parameters, ensuring that any exceptions that occur during
the execution of the given function are logged.
Expand All @@ -104,7 +105,7 @@ def run_main(main_fn: Callable[[], Any], format=LOG_DEFAULT_FORMAT, level=lg.DEB


# noinspection PyShadowingBuiltins
def run_cli(main_fn: Callable[[], Any], format=LOG_DEFAULT_FORMAT, level=lg.DEBUG):
def run_cli(main_fn: Callable[..., T], format: str = LOG_DEFAULT_FORMAT, level: int = lg.DEBUG) -> Optional[T]:
"""
Configures logging with the given parameters and runs the given main function as a
CLI using `jsonargparse` (which is configured to also parse attribute docstrings, such
Expand Down

0 comments on commit 9cf3c32

Please sign in to comment.