Skip to content
Myr

Allow self as an argument to url_for

Before adoption: this commit came in with the history the project adopted, so no landing records it.

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.

authored by pgjones · committed by Phil Jones · parent b7c1290 · Browse files · 3 files+9 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+9 added−0 removed

  • tests:+7 added−0 removed
  • other:+2 added−0 removed

3 files+9 added−0 removed

modified:src/flask/app.py+1 added
950 unmodified lines
951 return asgiref_async_to_sync(func)952953 def url_for(954 self,955 /,956 endpoint: str,957 *,958 _anchor: str | None = None,959 _method: str | None = None,
519 unmodified lines
modified:tests/test_helpers.py+7 added
159 unmodified lines
160 assert flask.url_for("myview", _method="GET") == "/myview/"161 assert flask.url_for("myview", id=42, _method="GET") == "/myview/42"162 assert flask.url_for("myview", _method="POST") == "/myview/create"163164 def test_url_for_with_self(self, app, req_ctx):165 @app.route("/<self>")166 def index(self):167 return "42"168169 assert flask.url_for("index", self="2") == "/2"170171172def test_redirect_no_app():173 response = flask.redirect("https://localhost", 307)174 assert response.location == "https://localhost"175 assert response.status_code == 307
174 unmodified lines
modified:CHANGES.rst+1 added
6 unmodified lines
7- Deprecate the ``__version__`` attribute. Use feature detection, or8 ``importlib.metadata.version("flask")``, instead. :issue:`5230`9- Restructure the code such that the Flask (app) and Blueprint10 classes have Sans-IO bases. :pr:`5127`11- Allow self as an argument to url_for. :pr:`5264`121314Version 2.3.315-------------
1514 unmodified lines