From 10184d1995223bb70d95de43c723fbabe03c08e7 Mon Sep 17 00:00:00 2001 From: Reinout van Rees Date: Tue, 12 Mar 2024 11:48:03 +0100 Subject: [PATCH] Fixed some more ruff stuff --- api/bro_upload/delivery.py | 3 +-- bro_hub/settings/development.py | 2 +- bro_hub/settings/production.py | 2 +- streamlit/authentication.py | 10 +++++++--- streamlit/utils.py | 6 +++++- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/api/bro_upload/delivery.py b/api/bro_upload/delivery.py index 83cdae4..26c3fe3 100644 --- a/api/bro_upload/delivery.py +++ b/api/bro_upload/delivery.py @@ -1,6 +1,5 @@ import time import traceback -from typing import Union from . import config, utils @@ -121,7 +120,7 @@ def _deliver_xml_file(self, xml_file: str) -> str: return delivery_url - def _check_delivery(self, delivery_url: str) -> Union[str, None]: + def _check_delivery(self, delivery_url: str) -> str | None: """Checks the delivery status.""" delivery_info = utils.check_delivery_status( diff --git a/bro_hub/settings/development.py b/bro_hub/settings/development.py index 3193656..10dd2cf 100644 --- a/bro_hub/settings/development.py +++ b/bro_hub/settings/development.py @@ -1,4 +1,4 @@ -from .base import * +from .base import * # noqa: F403 DEBUG = True diff --git a/bro_hub/settings/production.py b/bro_hub/settings/production.py index a0f8d5e..c285100 100644 --- a/bro_hub/settings/production.py +++ b/bro_hub/settings/production.py @@ -1,4 +1,4 @@ -from .base import * +from .base import * # noqa: F403 DEBUG = True diff --git a/streamlit/authentication.py b/streamlit/authentication.py index f09afe6..d857626 100644 --- a/streamlit/authentication.py +++ b/streamlit/authentication.py @@ -1,11 +1,13 @@ import json -from typing import Union +import logging import config import requests import streamlit as st +logger = logging.getLogger(__name__) + def is_authenticated() -> bool: """Returns `True` if the api token is set correctly to the session state.""" @@ -38,7 +40,7 @@ def check_credentials() -> None: return True -def get_api_token(username, password) -> Union[str, None]: +def get_api_token(username, password) -> str | None: """Uses the username and password combination to create an API token.""" url = f"{config.BASE_URL}/api/token/" headers = {"Content-Type": "application/json"} @@ -51,7 +53,9 @@ def get_api_token(username, password) -> Union[str, None]: data=json.dumps(payload), ) return r.json()["access"] - except: + except: # noqa: E722 + # TODO: fix bare except + logger.exception("get_api_token error") return None diff --git a/streamlit/utils.py b/streamlit/utils.py index 802d445..f5eb69c 100644 --- a/streamlit/utils.py +++ b/streamlit/utils.py @@ -1,3 +1,4 @@ +import logging from datetime import datetime, timedelta from typing import Any @@ -8,6 +9,8 @@ import streamlit as st +logger = logging.getLogger(__name__) + def set_user_details() -> None: """Saves the user details to the session state.""" @@ -90,7 +93,8 @@ def lookup_most_recent_datetime(endpoint: str) -> str: ) return last_update - except: + except: # noqa: E722 + logger.exception("TODO: bare except, fix this") return None