Skip to content

Conversation

@hrimov
Copy link

@hrimov hrimov commented Feb 8, 2025

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]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mypy: Blueprint type mismatch with flask.sansio.blueprints.Blueprint

1 participant