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

Split the App and Blueprint into Sansio and IO parts #5127

Merged
merged 8 commits into from Aug 20, 2023

Conversation

pgjones
Copy link
Member

@pgjones pgjones commented May 15, 2023

This follows a similar structure in Werkzeug and allows for async based IO projects, specifically Quart, to base themselves on Flask.

Note that the globals, and signals are specific to Flask and hence specific to Flask's IO. This means they cannot be moved to the sansio part of the codebase. (We may be able to change this in the future, but I think we should let this change settle first).

Checklist:

  • Add tests that demonstrate the correct behavior of the change. Tests should fail without the change.
  • Add or update relevant docs, in the docs folder and in code.
  • Add an entry in CHANGES.rst summarizing the change and linking to the issue.
  • Add .. versionchanged:: entries in any relevant code docs.
  • Run pre-commit hooks and fix any issues.
  • Run pytest and tox, no tests failed.

Copy link
Member Author

@pgjones pgjones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Split commits into file moves and refactoring commits.

src/flask/scaffold.py Outdated Show resolved Hide resolved
src/flask/_static_mixin.py Outdated Show resolved Hide resolved
@pgjones pgjones changed the title Split the Scaffold and Blueprint into Sansio and IO parts Split the App and Blueprint into Sansio and IO parts Jun 11, 2023
@pgjones pgjones force-pushed the sansio branch 2 times, most recently from 194b16d to c247d3a Compare June 11, 2023 14:07
@pgjones pgjones marked this pull request as ready for review August 15, 2023 07:30
@pgjones pgjones force-pushed the sansio branch 3 times, most recently from 6938ade to 751777f Compare August 15, 2023 14:16
@davidism davidism added this to the 3.0.0 milestone Aug 16, 2023
src/flask/app.py Outdated Show resolved Hide resolved
@davidism
Copy link
Member

Should be able to rebase to fix the pre-commit failure.

@davidism
Copy link
Member

davidism commented Aug 19, 2023

Remind me what the issue with sharing current_app and request is? Was it typing?

This is preperation for refactoring the files so that there are sansio
and flask specific versions. This structure follows the Werkzeug
structure/pattern.
This follows a similar structure in Werkzeug and allows for async
based IO projects, specifically Quart, to base themselves on
Flask.

Note that the globals, and signals are specific to Flask and hence
specific to Flask's IO. This means they cannot be moved to the sansio
part of the codebase.
This allows a Blueprint implementation that has additional funcs, such
as Quart with its before_websocket_funcs (as example), to extend the
merge method to also merge these functions.
This is useful as there is contextual information that could be loaded
via IO e.g. information from a database. This also matches Quart and
hence makes the shared signature easier to manage.
Whilst not strictly true for Flask, it is true for Flask and Quart and
hence makes it much easier for Quart to extend Flask classes. The
alternatives are generic usage in the sansio codebase or mixed usage
within Flask. I think this is a good compromise.
It may also be awaitable, as invocations are wrapped in ensure_sync.
This should hopefully explain what it is used for and why certain code
cannot be present in it.
@pgjones
Copy link
Member Author

pgjones commented Aug 19, 2023

Remind me what the issue with sharing current_app and request is? Was it typing?

Partially, as the wrong type does make things difficult for users. Which on a related typing note, I think the next step for this (ideally post merge) is to make the sansio parts Generic in the response return type, to allow for Quart to use async iterators (which is too hard I think in Flask to achieve) and for Flask's typing to again be narrowed.

The main issue is I'd like to keep https://github.com/pgjones/quart-flask-patch working, which will require flask's current_app and request to be different instances to quart's.

@davidism davidism merged commit 1d8b53f into pallets:main Aug 20, 2023
13 checks passed
@pgjones pgjones deleted the sansio branch August 20, 2023 16:32
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants