quart
quart copied to clipboard
Fix `app.blueprints` type annotation
Add quart.blueprints.Blueprint type annotation for the blueprints property instead of the inherited flask.sansio.blueprints.Blueprint type.
fixes #404
With a given MRE:
from quart import Quart
from quart.blueprints import Blueprint
app = Quart(__name__)
bp = Blueprint("test", __name__)
app.register_blueprint(bp)
# This works at runtime but fails type check
def process_blueprint(blueprint: Blueprint) -> None:
print(f"Processing blueprint: {blueprint.name}")
# Type error here - blueprints.values() returns flask.sansio.blueprints.Blueprint
for blueprint in app.blueprints.values():
process_blueprint(blueprint) # Error: Expected quart.blueprints.Blueprint, got flask.sansio.blueprints.Blueprint
# Show inferred types
reveal_type(bp) # Shows quart.blueprints.Blueprint
reveal_type(app.blueprints) # Now it shows Dict[str,quart.blueprints.Blueprint] instead of Dict[str, flask.sansio.blueprints.Blueprint]