Skip to content

Commit

Permalink
Fixing types
Browse files Browse the repository at this point in the history
  • Loading branch information
djpugh committed Dec 16, 2020
1 parent 7d23fc1 commit 22d2061
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/fastapi_aad_auth/utilities/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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]
Expand All @@ -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}``]'
Expand Down

0 comments on commit 22d2061

Please sign in to comment.