Skip to content
Myr

add example code for testing typing tools

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by lecovi · committed by David Lord · parent 21d32ee · Browse files · 1 file+53 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+53 added−0 removed

  • tests:+53 added−0 removed

1 file+53 added−0 removed

added:tests/typing/typing_route.py+53 added
1from http import HTTPStatus2from typing import Tuple3from typing import Union45from flask import Flask6from flask import jsonify7from flask.templating import render_template8from flask.views import View9from flask.wrappers import Response101112app = Flask(__name__)131415@app.route("/")16def hello_world() -> str:17 return "<p>Hello, World!</p>"181920@app.route("/json")21def hello_world_json() -> Response:22 return jsonify({"response": "Hello, World!"})232425@app.route("/template")26@app.route("/template/<name>")27def return_template(name: Union[str, None] = None) -> str:28 return render_template("index.html", name=name)293031@app.errorhandler(HTTPStatus.INTERNAL_SERVER_ERROR)32def error_500(e) -> Tuple[str, int]:33 return "<p>Sorry, we are having problems</p>", HTTPStatus.INTERNAL_SERVER_ERROR343536@app.before_request37def before_request() -> None:38 app.logger.debug("Executing a sample before_request function")39 return None404142class RenderTemplateView(View):43 def __init__(self: "RenderTemplateView", template_name: str) -> None:44 self.template_name = template_name4546 def dispatch_request(self: "RenderTemplateView") -> str:47 return render_template(self.template_name)484950app.add_url_rule(51 "/about",52 view_func=RenderTemplateView.as_view("about_page", template_name="about.html"),53)