mirror of
https://github.com/theroyallab/tabbyAPI.git
synced 2026-03-15 00:07:28 +00:00
add legacy config converter
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user