Skip to content

Commit 4580593

Browse files
Support Flask 2.3 (#189)
* Constrain Flask temp workaround to prevent the error after downgrading Flask as in #188 (better would be to support Flask 2.3 and not use deprecated features) * Fix examples, support Flask 2.3 --------- Co-authored-by: Replit user <>
1 parent b72072e commit 4580593

File tree

6 files changed

+9
-7
lines changed

6 files changed

+9
-7
lines changed

examples/web/authenticated.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ def test():
2020

2121

2222
if __name__ == "__main__":
23-
web.run_app(app)
23+
web.run(app)

examples/web/manual_auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ def index():
1717

1818

1919
if __name__ == "__main__":
20-
web.run_app(app)
20+
web.run(app)

examples/web/needs_params.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ def query(q):
4545

4646

4747
if __name__ == "__main__":
48-
web.run_app(app)
48+
web.run(app)

examples/web/ratelimit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ def index():
1919

2020

2121
if __name__ == "__main__":
22-
web.run_app(app)
22+
web.run(app)

src/replit/web/app.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ def run(
5959
) -> None:
6060
"""A simple wrapper around app.run() with replit compatible defaults."""
6161
# don't clobber user
62-
if change_encoder and app.json_encoder is flask.json.JSONEncoder:
62+
if change_encoder and getattr(app, "json_encoder", None) is getattr(
63+
flask.json, "json_encoder", None
64+
):
6365
app.json_encoder = DBJSONEncoder
6466
app.run(host=host, port=port, **kwargs)
6567

src/replit/web/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def per_user_ratelimit(
179179
get_ratelimited_res: Callable[[float], str] = (
180180
lambda left: f"Too many requests, wait {left} sec"
181181
),
182-
) -> Callable[[Callable], flask.Response]:
182+
) -> Callable[[Callable], Callable[[Callable], flask.Response]]:
183183
"""Require sign in and limit the amount of requests each signed in user can perform.
184184
185185
This decorator also calls needs_signin for you and passes the login_res kwarg
@@ -200,7 +200,7 @@ def per_user_ratelimit(
200200
last_reset = time.time()
201201
num_requests = {}
202202

203-
def decorator(func: Callable) -> flask.Response:
203+
def decorator(func: Callable) -> Callable[..., flask.Response]:
204204
# Checks for signin first, before checking ratelimit
205205
@authenticated(login_res=login_res)
206206
@wraps(func)

0 commit comments

Comments
 (0)