Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix app.blueprints type annotation #405

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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