add legacy config converter

This commit is contained in:
TerminalMan
2024-09-16 14:12:47 +01:00
parent b6dd21f737
commit 564bdcf0a8
4 changed files with 71 additions and 19 deletions

View File

@@ -1,6 +1,7 @@
"""Common utility functions"""
from typing import get_args, get_origin
from types import NoneType
from typing import Optional, Type, Union, get_args, get_origin
def unwrap(wrapped, default=None):
@@ -47,7 +48,7 @@ def flat_map(input_list):
return [item for sublist in input_list for item in sublist]
def is_list_type(type_hint):
def is_list_type(type_hint) -> bool:
"""Checks if a type contains a list."""
if get_origin(type_hint) is list:
@@ -59,3 +60,16 @@ def is_list_type(type_hint):
return any(is_list_type(arg) for arg in type_args)
return False
def unwrap_optional(type_hint) -> Type:
"""unwrap Optional[type] annotations"""
if get_origin(type_hint) is Union:
args = get_args(type_hint)
if NoneType in args:
for arg in args:
if arg is not NoneType:
return arg
return type_hint