Skip to content

Commit

Permalink
Support Flask 2.3 (#189)
Browse files Browse the repository at this point in the history
* 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 <>
  • Loading branch information
noneofyourbusiness1415252 authored Dec 8, 2023
1 parent b72072e commit 4580593
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion examples/web/authenticated.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ def test():


if __name__ == "__main__":
web.run_app(app)
web.run(app)
2 changes: 1 addition & 1 deletion examples/web/manual_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ def index():


if __name__ == "__main__":
web.run_app(app)
web.run(app)
2 changes: 1 addition & 1 deletion examples/web/needs_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ def query(q):


if __name__ == "__main__":
web.run_app(app)
web.run(app)
2 changes: 1 addition & 1 deletion examples/web/ratelimit.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ def index():


if __name__ == "__main__":
web.run_app(app)
web.run(app)
4 changes: 3 additions & 1 deletion src/replit/web/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ def run(
) -> None:
"""A simple wrapper around app.run() with replit compatible defaults."""
# don't clobber user
if change_encoder and app.json_encoder is flask.json.JSONEncoder:
if change_encoder and getattr(app, "json_encoder", None) is getattr(
flask.json, "json_encoder", None
):
app.json_encoder = DBJSONEncoder
app.run(host=host, port=port, **kwargs)

Expand Down
4 changes: 2 additions & 2 deletions src/replit/web/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def per_user_ratelimit(
get_ratelimited_res: Callable[[float], str] = (
lambda left: f"Too many requests, wait {left} sec"
),
) -> Callable[[Callable], flask.Response]:
) -> Callable[[Callable], Callable[[Callable], flask.Response]]:
"""Require sign in and limit the amount of requests each signed in user can perform.
This decorator also calls needs_signin for you and passes the login_res kwarg
Expand All @@ -200,7 +200,7 @@ def per_user_ratelimit(
last_reset = time.time()
num_requests = {}

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

0 comments on commit 4580593

Please sign in to comment.