diff --git a/spaceapi/auth.py b/spaceapi/auth.py --- a/spaceapi/auth.py +++ b/spaceapi/auth.py @@ -1,5 +1,5 @@ from hmac import compare_digest -from typing import Optional +from typing import Optional, cast from flask import current_app from flask_httpauth import HTTPBasicAuth, HTTPDigestAuth @@ -11,7 +11,7 @@ httpauth = HTTPDigestAuth() @httpauth.get_password def get_pw(username: str) -> Optional[str]: if username in current_app.config["HTTP_DIGEST_AUTH_USERS"]: - return current_app.config["HTTP_DIGEST_AUTH_USERS"][username] + return cast(str, current_app.config["HTTP_DIGEST_AUTH_USERS"][username]) return None diff --git a/spaceapi/sensors.py b/spaceapi/sensors.py --- a/spaceapi/sensors.py +++ b/spaceapi/sensors.py @@ -1,7 +1,8 @@ import json +from typing import Any, Dict, cast import jsonschema -from flask import Blueprint, abort, current_app, jsonify, request +from flask import Blueprint, Response, abort, current_app, jsonify, request from pkg_resources import resource_filename from .auth import httpauth @@ -16,12 +17,12 @@ ALLOWED_SENSORS_KEYS = json.load( @sensors_views.route("/set/", methods=["POST"]) @httpauth.login_required -def set_sensors(key): +def set_sensors(key: str) -> Response: active = ActiveStatusv14() if key in ALLOWED_SENSORS_KEYS and key in active["sensors"]: - data = request.json + data = cast(Dict[str, Any], request.json) try: try: jsonschema.validate(data, ALLOWED_SENSORS_KEYS[key]) diff --git a/spaceapi/utils.py b/spaceapi/utils.py --- a/spaceapi/utils.py +++ b/spaceapi/utils.py @@ -54,11 +54,11 @@ RADIATON_SUBKEYS = frozenset(("alpha", " class Singleton: - def __new__(cls, *args, **kwargs): + def __new__(cls, *args: Any, **kwargs: Any) -> Any: key = str(hash(cls)) if not hasattr(cls, "_instance_dict"): - cls._instance_dict = {} + cls._instance_dict = {} # type: Dict[str, Any] if key not in cls._instance_dict: cls._instance_dict[key] = super().__new__(cls, *args, **kwargs) @@ -67,7 +67,7 @@ class Singleton: class ActiveStatusv14(Singleton, dict): - def __init__(self): + def __init__(self) -> None: self.default_json_file = default_json_file_v14 self.last_state_file = last_state_file_v14