mirror of
https://github.com/Garmelon/PFERD.git
synced 2023-12-21 10:23:01 +01:00
Correctly type hint swallow_and_print_errors decorator
This commit is contained in:
parent
072c6630bf
commit
03a801eecc
@ -3,7 +3,7 @@ An error logging decorator.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from typing import Any, Callable
|
from typing import Any, Callable, TypeVar, cast
|
||||||
|
|
||||||
from rich.console import Console
|
from rich.console import Console
|
||||||
|
|
||||||
@ -19,7 +19,10 @@ class FatalException(Exception):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
def swallow_and_print_errors(function: Callable) -> Callable:
|
TFun = TypeVar('TFun', bound=Callable[..., Any])
|
||||||
|
|
||||||
|
|
||||||
|
def swallow_and_print_errors(function: TFun) -> TFun:
|
||||||
"""
|
"""
|
||||||
Decorates a function, swallows all errors, logs them and returns none if one occurred.
|
Decorates a function, swallows all errors, logs them and returns none if one occurred.
|
||||||
"""
|
"""
|
||||||
@ -33,4 +36,4 @@ def swallow_and_print_errors(function: Callable) -> Callable:
|
|||||||
except Exception as error:
|
except Exception as error:
|
||||||
Console().print_exception()
|
Console().print_exception()
|
||||||
return None
|
return None
|
||||||
return inner
|
return cast(TFun, inner)
|
||||||
|
@ -2,6 +2,7 @@ import argparse
|
|||||||
from pathlib import Path, PurePath
|
from pathlib import Path, PurePath
|
||||||
|
|
||||||
from PFERD import Pferd
|
from PFERD import Pferd
|
||||||
|
from PFERD.ilias import IliasDirectoryType
|
||||||
from PFERD.transform import (attempt, do, glob, keep, move, move_dir,
|
from PFERD.transform import (attempt, do, glob, keep, move, move_dir,
|
||||||
optionally, re_move, re_rename)
|
optionally, re_move, re_rename)
|
||||||
|
|
||||||
@ -48,7 +49,7 @@ tf_ss_2020_pg = attempt(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def df_ss_2020_or1(path: PurePath) -> bool:
|
def df_ss_2020_or1(path: PurePath, _type: IliasDirectoryType) -> bool:
|
||||||
if glob("Tutorien/")(path):
|
if glob("Tutorien/")(path):
|
||||||
return True
|
return True
|
||||||
if glob("Tutorien/Tutorium 10, dienstags 15:45 Uhr/")(path):
|
if glob("Tutorien/Tutorium 10, dienstags 15:45 Uhr/")(path):
|
||||||
|
Loading…
Reference in New Issue
Block a user