Код: Выделить всё
import functools
from http import HTTPStatus
import flask
from flask.typing import ResponseReturnType
app = flask.Flask(__name__)
# What type hints should be added to this?
def requires_header(func):
@functools.wraps(func)
def check_headers(*args, **kwargs):
if not flask.request.headers.get("X-Foo"):
flask.abort(HTTPStatus.NOT_FOUND)
return func(*args, **kwargs)
return check_headers
@app.route("/", methods=["GET"])
@requires_header
def root() -> ResponseReturnType:
return flask.jsonify(success=True)
if __name__ == "__main__":
flask.run(host=0.0.0.0, port=3000)
Подробнее здесь: https://stackoverflow.com/questions/694 ... pe-hinting