From 22d206116b4b149aecfa697529ab168b0ac22d51 Mon Sep 17 00:00:00 2001 From: David Pugh Date: Wed, 16 Dec 2020 08:41:56 +0000 Subject: [PATCH] Fixing types --- src/fastapi_aad_auth/utilities/__init__.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/fastapi_aad_auth/utilities/__init__.py b/src/fastapi_aad_auth/utilities/__init__.py index bd262df..ba8ea64 100644 --- a/src/fastapi_aad_auth/utilities/__init__.py +++ b/src/fastapi_aad_auth/utilities/__init__.py @@ -1,6 +1,8 @@ """Utilities.""" import importlib +from typing import List, Union +from pydantic.main import ModelMetaclass from starlette.requests import Request from fastapi_aad_auth.utilities import logging # noqa: F401 @@ -13,14 +15,14 @@ def is_interactive(request: Request): return any([u in request.headers['user-agent'] for u in ['Mozilla', 'Gecko', 'Trident', 'WebKit', 'Presto', 'Edge', 'Blink']]) -def bool_from_env(env_value: str): +def bool_from_env(env_value: Union[bool, str]) -> bool: """Convert environment variable to boolean.""" if isinstance(env_value, str): env_value = env_value.lower() in ['true', '1'] return env_value -def list_from_env(env_value: str): +def list_from_env(env_value: Union[List[str], str]) -> List[str]: """Convert environment variable to list.""" if isinstance(env_value, str): env_value = [u for u in env_value.split(',') if u] @@ -41,10 +43,10 @@ def klass_from_str(value: str): return value -def expand_doc(klass: type): +def expand_doc(klass: ModelMetaclass) -> ModelMetaclass: """Expand pydantic model documentation to enable autodoc.""" docs = ['', '', 'Keyword Args:'] - for name, field in klass.__fields__.items(): + for name, field in klass.__fields__.items(): # type: ignore default_str = '' if field.default: default_str = f' [default: ``{field.default}``]'