Home / File/ typing_route.py — flask Source File

typing_route.py — flask Source File

Architecture documentation for typing_route.py, a python file in the flask codebase. 6 imports, 0 dependents.

File python ApplicationCore ExtensionRegistry 6 imports 15 functions 2 classes

Entity Profile

Dependency Diagram

graph LR
  51f1ce6f_d4e0_b1a0_7ac9_cf9cfb347ede["typing_route.py"]
  852dc50b_4da6_57dc_ead7_cdd90925e0b8["typing"]
  51f1ce6f_d4e0_b1a0_7ac9_cf9cfb347ede --> 852dc50b_4da6_57dc_ead7_cdd90925e0b8
  3f1acc4c_dd91_cc8b_9adb_2e2510ee025f["http"]
  51f1ce6f_d4e0_b1a0_7ac9_cf9cfb347ede --> 3f1acc4c_dd91_cc8b_9adb_2e2510ee025f
  8c762fc5_c0b6_0d4d_3889_896d80fbf225["flask"]
  51f1ce6f_d4e0_b1a0_7ac9_cf9cfb347ede --> 8c762fc5_c0b6_0d4d_3889_896d80fbf225
  0036ff2f_2d2f_5c1e_a70a_20bf21fd3742["flask.templating"]
  51f1ce6f_d4e0_b1a0_7ac9_cf9cfb347ede --> 0036ff2f_2d2f_5c1e_a70a_20bf21fd3742
  eda0cf94_ef01_1441_96fa_d1dc0c43581a["flask.views"]
  51f1ce6f_d4e0_b1a0_7ac9_cf9cfb347ede --> eda0cf94_ef01_1441_96fa_d1dc0c43581a
  704b0046_1aa5_0134_121a_5ca001a91d65["flask.wrappers"]
  51f1ce6f_d4e0_b1a0_7ac9_cf9cfb347ede --> 704b0046_1aa5_0134_121a_5ca001a91d65
  style 51f1ce6f_d4e0_b1a0_7ac9_cf9cfb347ede fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

from __future__ import annotations

import typing as t
from http import HTTPStatus

from flask import Flask
from flask import jsonify
from flask import stream_template
from flask.templating import render_template
from flask.views import View
from flask.wrappers import Response

app = Flask(__name__)


@app.route("/str")
def hello_str() -> str:
    return "<p>Hello, World!</p>"


@app.route("/bytes")
def hello_bytes() -> bytes:
    return b"<p>Hello, World!</p>"


@app.route("/json")
def hello_json() -> Response:
    return jsonify("Hello, World!")


@app.route("/json/dict")
def hello_json_dict() -> dict[str, t.Any]:
    return {"response": "Hello, World!"}


@app.route("/json/dict")
def hello_json_list() -> list[t.Any]:
    return [{"message": "Hello"}, {"message": "World"}]


class StatusJSON(t.TypedDict):
    status: str


@app.route("/typed-dict")
def typed_dict() -> StatusJSON:
    return {"status": "ok"}


@app.route("/generator")
def hello_generator() -> t.Generator[str, None, None]:
    def show() -> t.Generator[str, None, None]:
        for x in range(100):
            yield f"data:{x}\n\n"

    return show()


@app.route("/generator-expression")
def hello_generator_expression() -> t.Iterator[bytes]:
    return (f"data:{x}\n\n".encode() for x in range(100))


@app.route("/iterator")
def hello_iterator() -> t.Iterator[str]:
    return iter([f"data:{x}\n\n" for x in range(100)])


@app.route("/status")
@app.route("/status/<int:code>")
def tuple_status(code: int = 200) -> tuple[str, int]:
    return "hello", code


@app.route("/status-enum")
def tuple_status_enum() -> tuple[str, int]:
    return "hello", HTTPStatus.OK


@app.route("/headers")
def tuple_headers() -> tuple[str, dict[str, str]]:
    return "Hello, World!", {"Content-Type": "text/plain"}


@app.route("/template")
@app.route("/template/<name>")
def return_template(name: str | None = None) -> str:
    return render_template("index.html", name=name)


@app.route("/template")
def return_template_stream() -> t.Iterator[str]:
    return stream_template("index.html", name="Hello")


@app.route("/async")
async def async_route() -> str:
    return "Hello"


class RenderTemplateView(View):
    def __init__(self: RenderTemplateView, template_name: str) -> None:
        self.template_name = template_name

    def dispatch_request(self: RenderTemplateView) -> str:
        return render_template(self.template_name)


app.add_url_rule(
    "/about",
    view_func=RenderTemplateView.as_view("about_page", template_name="about.html"),
)

Subdomains

Dependencies

  • flask
  • flask.templating
  • flask.views
  • flask.wrappers
  • http
  • typing

Frequently Asked Questions

What does typing_route.py do?
typing_route.py is a source file in the flask codebase, written in python. It belongs to the ApplicationCore domain, ExtensionRegistry subdomain.
What functions are defined in typing_route.py?
typing_route.py defines 15 function(s): async_route, hello_bytes, hello_generator, hello_generator_expression, hello_iterator, hello_json, hello_json_dict, hello_json_list, hello_str, return_template, and 5 more.
What does typing_route.py depend on?
typing_route.py imports 6 module(s): flask, flask.templating, flask.views, flask.wrappers, http, typing.
Where is typing_route.py in the architecture?
typing_route.py is located at tests/type_check/typing_route.py (domain: ApplicationCore, subdomain: ExtensionRegistry, directory: tests/type_check).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free