Commit graph

15 commits

Author SHA1 Message Date
Alex Hedges
9841b21f4b Make add_url_rule() signature consistent
This caused a mypy error when I was making another typing improvement,
so I am fixing it before committing my other changes.
2021-05-21 08:09:05 +00:00
Grey Li
702529eb9c improve type hints for send_file and send_from_directory 2021-05-13 13:33:07 -07:00
pgjones
271eede7ad Simplify the async handling code
Firstly `run_sync` was a misleading name as it didn't run anything,
instead I think `async_to_sync` is much clearer as it converts a
coroutine function to a function. (Name stolen from asgiref).

Secondly trying to run the ensure_sync during registration made the
code more complex and brittle, e.g. the _flask_async_wrapper
usage. This was done to pay any setup costs during registration rather
than runtime, however this only saved a iscoroutne check. It allows
the weirdness of the Blueprint and Scaffold ensure_sync methods to be
removed.

Switching to runtime ensure_sync usage provides a method for
extensions to also support async, as now documented.
2021-05-03 06:15:39 -07:00
Adrian Moennich
d12bc54013 Move get_root_path back to flask.helpers
Many libraries use it so the move is somewhat disruptive.
2021-04-27 16:42:16 +02:00
pgjones
fa5c99ef4f Add initial type hints
This should make it easier for users to correctly use Flask. The hints
are from Quart.
2021-04-26 17:29:53 +01:00
David Lord
d0076a527d consistent versions and deprecation messages 2021-04-15 15:58:24 -07:00
pgjones
d65f574bff Alter ensure_sync implementation to support extensions
This allows extensions to override the Flask.ensure_sync method and
have the change apply to blueprints as well. Without this change it is
possible for differing blueprints to have differing ensure_sync
approaches depending on the extension used - which would likely result
in event-loop blocking issues.

This also allows blueprints to have a custom ensure_sync, although
this is a by product rather than an expected use case.
2021-04-06 15:33:06 -07:00
pgjones
c9f774d650 Add async support
This allows for async functions to be passed to the Flask class
instance, for example as a view function,

    @app.route("/")
    async def index():
        return "Async hello"

this comes with a cost though of poorer performance than using the
sync equivalent.

asgiref is the standard way to run async code within a sync context,
and is used in Django making it a safe and sane choice for this.
2021-04-06 09:35:10 -07:00
David Lord
8e0d511d12 remove redundant _register_error_handler 2021-03-10 10:38:17 -08:00
David Lord
8bf05e1b1d rewrite Scaffold docs 2021-03-10 10:38:16 -08:00
David Lord
d9db703c8a move _PackageBoundObject into Scaffold 2021-03-10 10:38:13 -08:00
pgjones
708623907d Utilise defaultdicts
This code originates from the Python 2.4 supporting version of Flask,
with defaultdicts being added in 2.5. Using defaultdict makes the
intentional usage clearer, and slightly simplifies the code.
2021-03-08 09:58:12 -08:00
pgjones
26932dad46 Add syntatic sugar for route registration
This takes a popular API whereby instead of passing the HTTP method as
an argument to route it is instead used as the method name i.e.

    @app.route("/", methods=["POST"])

is now writeable as,

    @app.post("/")

This is simply syntatic sugar, it doesn't do anything else, but makes
it slightly easier for users.

I've included all the methods that are relevant and aren't auto
generated i.e. not connect, head, options, and trace.
2021-03-08 08:55:14 -08:00
David Lord
8817c77eb0 update requirements (#3823) 2020-11-01 05:30:02 -08:00
yk396
a37cbe4fbb extract common Flask/Blueprint API to Scaffold base class
Co-authored-by: Chris Nguyen <chrisngyn99@gmail.com>
2020-08-01 07:45:58 -07:00