Skip to content

Commit

Permalink
Allow self as an argument to url_for
Browse files Browse the repository at this point in the history
This makes the Flask.url_for self argument positional only (Flask
supports Python 3.8+) thereby restoring the ability to pass self as a
value argument to url_for.
  • Loading branch information
pgjones committed Sep 24, 2023
1 parent b7c1290 commit 481afe5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/flask/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,7 @@ def async_to_sync(

def url_for(
self,
/,
endpoint: str,
*,
_anchor: str | None = None,
Expand Down
7 changes: 7 additions & 0 deletions tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,13 @@ def post(self):
assert flask.url_for("myview", id=42, _method="GET") == "/myview/42"
assert flask.url_for("myview", _method="POST") == "/myview/create"

def test_url_for_with_self(self, app, req_ctx):
@app.route("/<self>")
def index(self):
return "42"

assert flask.url_for("index", self="2") == "/2"


def test_redirect_no_app():
response = flask.redirect("https://localhost", 307)
Expand Down

0 comments on commit 481afe5

Please sign in to comment.