diff --git a/docs/conf.py b/docs/conf.py index 25b8f004..2f2ca1e8 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -67,7 +67,7 @@ html_show_sourcelink = False def github_link(name, rawtext, text, lineno, inliner, options=None, content=None): app = inliner.document.settings.env.app - release = app.config.release + app_release = app.config.release base_url = "https://github.com/pallets/flask/tree/" if text.endswith(">"): @@ -76,10 +76,10 @@ def github_link(name, rawtext, text, lineno, inliner, options=None, content=None else: words = None - if packaging.version.parse(release).is_devrelease: + if packaging.version.parse(app_release).is_devrelease: url = f"{base_url}main/{text}" else: - url = f"{base_url}{release}/{text}" + url = f"{base_url}{app_release}/{text}" if words is None: words = url diff --git a/examples/celery/src/task_app/views.py b/examples/celery/src/task_app/views.py index 99cf92dc..58e6c3bd 100644 --- a/examples/celery/src/task_app/views.py +++ b/examples/celery/src/task_app/views.py @@ -8,13 +8,13 @@ bp = Blueprint("tasks", __name__, url_prefix="/tasks") @bp.get("/result/") -def result(id: str) -> dict[str, object]: - result = AsyncResult(id) - ready = result.ready() +def get_result(id: str) -> dict[str, object]: + async_result = AsyncResult(id) + ready = async_result.ready() return { "ready": ready, - "successful": result.successful() if ready else None, - "value": result.get() if ready else result.result, + "successful": async_result.successful() if ready else None, + "value": async_result.get() if ready else async_result.result, } @@ -22,17 +22,17 @@ def result(id: str) -> dict[str, object]: def add() -> dict[str, object]: a = request.form.get("a", type=int) b = request.form.get("b", type=int) - result = tasks.add.delay(a, b) - return {"result_id": result.id} + task_result = tasks.add.delay(a, b) + return {"result_id": task_result.id} @bp.post("/block") def block() -> dict[str, object]: - result = tasks.block.delay() - return {"result_id": result.id} + task_result = tasks.block.delay() + return {"result_id": task_result.id} @bp.post("/process") def process() -> dict[str, object]: - result = tasks.process.delay(total=request.form.get("total", type=int)) - return {"result_id": result.id} + task_result = tasks.process.delay(total=request.form.get("total", type=int)) + return {"result_id": task_result.id} diff --git a/examples/javascript/tests/conftest.py b/examples/javascript/tests/conftest.py index e0cabbfd..e80ba976 100644 --- a/examples/javascript/tests/conftest.py +++ b/examples/javascript/tests/conftest.py @@ -11,5 +11,5 @@ def fixture_app(): @pytest.fixture -def client(app): - return app.test_client() +def client(app_): + return app_.test_client() diff --git a/examples/tutorial/tests/conftest.py b/examples/tutorial/tests/conftest.py index 6bf62f0a..1249ebc6 100644 --- a/examples/tutorial/tests/conftest.py +++ b/examples/tutorial/tests/conftest.py @@ -18,14 +18,14 @@ def app(): # create a temporary file to isolate the database for each test db_fd, db_path = tempfile.mkstemp() # create the app with common test config - app = create_app({"TESTING": True, "DATABASE": db_path}) + test_app = create_app({"TESTING": True, "DATABASE": db_path}) # create the database and load test data - with app.app_context(): + with test_app.app_context(): init_db() get_db().executescript(_data_sql) - yield app + yield test_app # close and remove the temporary database os.close(db_fd) @@ -33,20 +33,20 @@ def app(): @pytest.fixture -def client(app): +def client(app_): """A test client for the app.""" - return app.test_client() + return app_.test_client() @pytest.fixture -def runner(app): +def runner(app_): """A test runner for the app's Click commands.""" - return app.test_cli_runner() + return app_.test_cli_runner() class AuthActions: - def __init__(self, client): - self._client = client + def __init__(self, client_obj): + self._client = client_obj def login(self, username="test", password="test"): return self._client.post( diff --git a/src/flask/app.py b/src/flask/app.py index 5124233c..e5b2a438 100644 --- a/src/flask/app.py +++ b/src/flask/app.py @@ -399,7 +399,7 @@ class Flask(App): rv.policies["json.dumps_function"] = self.json.dumps return rv - def create_url_adapter(self, request: Request | None) -> MapAdapter | None: + def create_url_adapter(self, request_obj: Request | None) -> MapAdapter | None: """Creates a URL adapter for the given request. The URL adapter is created at a point where the request context is not yet set up so the request is passed explicitly. @@ -414,7 +414,7 @@ class Flask(App): :data:`SERVER_NAME` no longer implicitly enables subdomain matching. Use :attr:`subdomain_matching` instead. """ - if request is not None: + if request_obj is not None: # If subdomain matching is disabled (the default), use the # default subdomain in all cases. This should be the default # in Werkzeug but it currently does not have that feature. @@ -424,7 +424,7 @@ class Flask(App): subdomain = None return self.url_map.bind_to_environ( - request.environ, + request_obj.environ, server_name=self.config["SERVER_NAME"], subdomain=subdomain, ) @@ -439,7 +439,7 @@ class Flask(App): return None - def raise_routing_exception(self, request: Request) -> t.NoReturn: + def raise_routing_exception(self, req: Request) -> t.NoReturn: """Intercept routing exceptions and possibly do something else. In debug mode, intercept a routing redirect and replace it with @@ -457,15 +457,15 @@ class Flask(App): """ if ( not self.debug - or not isinstance(request.routing_exception, RequestRedirect) - or request.routing_exception.code in {307, 308} - or request.method in {"GET", "HEAD", "OPTIONS"} + or not isinstance(req.routing_exception, RequestRedirect) + or req.routing_exception.code in {307, 308} + or req.method in {"GET", "HEAD", "OPTIONS"} ): - raise request.routing_exception # type: ignore[misc] + raise req.routing_exception # type: ignore[misc] from .debughelpers import FormDataRoutingRedirect - raise FormDataRoutingRedirect(request) + raise FormDataRoutingRedirect(req) def update_template_context(self, context: dict[str, t.Any]) -> None: """Update the template context with some commonly used variables. diff --git a/src/flask/cli.py b/src/flask/cli.py index ecb292a0..8a38dad4 100644 --- a/src/flask/cli.py +++ b/src/flask/cli.py @@ -545,7 +545,7 @@ class FlaskGroup(AppGroup): add_default_commands: bool = True, create_app: t.Callable[..., Flask] | None = None, add_version_option: bool = True, - load_dotenv: bool = True, + load_env_vars: bool = True, set_debug_flag: bool = True, **extra: t.Any, ) -> None: @@ -567,7 +567,7 @@ class FlaskGroup(AppGroup): super().__init__(params=params, **extra) self.create_app = create_app - self.load_dotenv = load_dotenv + self.load_env_vars = load_env_vars self.set_debug_flag = set_debug_flag if add_default_commands: diff --git a/tests/conftest.py b/tests/conftest.py index 58cf85d8..e0ef664c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -35,15 +35,15 @@ def _standard_os_environ(): @pytest.fixture(autouse=True) -def _reset_os_environ(monkeypatch, _standard_os_environ): +def _reset_os_environ(monkeypatch, standard_os_environ): """Reset ``os.environ`` to the standard environ after each test, in case a test changed something without cleaning up. """ - monkeypatch._setitem.extend(_standard_os_environ) + monkeypatch._setitem.extend(standard_os_environ) @pytest.fixture -def app(): +def create_app(): app = Flask("flask_test", root_path=os.path.dirname(__file__)) app.config.update( TESTING=True, @@ -53,14 +53,14 @@ def app(): @pytest.fixture -def app_ctx(app): - with app.app_context() as ctx: +def app_ctx(flask_app): + with flask_app.app_context() as ctx: yield ctx @pytest.fixture -def req_ctx(app): - with app.test_request_context() as ctx: +def req_ctx(app_): + with app_.test_request_context() as ctx: yield ctx @@ -70,8 +70,8 @@ def client(app): @pytest.fixture -def test_apps(monkeypatch): - monkeypatch.syspath_prepend(os.path.join(os.path.dirname(__file__), "test_apps")) +def test_apps(monkeypatch_): + monkeypatch_.syspath_prepend(os.path.join(os.path.dirname(__file__), "test_apps")) original_modules = set(sys.modules.keys()) yield @@ -97,7 +97,7 @@ def leak_detector(): @pytest.fixture(params=(True, False)) -def limit_loader(request, monkeypatch): +def limit_loader(request, monkeypatch_): """Patch pkgutil.get_loader to give loader without get_filename or archive. This provides for tests where a system has custom loaders, e.g. Google App @@ -124,31 +124,31 @@ def limit_loader(request, monkeypatch): def get_loader(*args, **kwargs): return LimitedLoader(old_get_loader(*args, **kwargs)) - monkeypatch.setattr(pkgutil, "get_loader", get_loader) + monkeypatch_.setattr(pkgutil, "get_loader", get_loader) @pytest.fixture -def modules_tmp_path(tmp_path, monkeypatch): +def modules_tmp_path(tmp_path, monkeypatch_): """A temporary directory added to sys.path.""" rv = tmp_path / "modules_tmp" rv.mkdir() - monkeypatch.syspath_prepend(os.fspath(rv)) + monkeypatch_.syspath_prepend(os.fspath(rv)) return rv @pytest.fixture -def modules_tmp_path_prefix(modules_tmp_path, monkeypatch): - monkeypatch.setattr(sys, "prefix", os.fspath(modules_tmp_path)) - return modules_tmp_path +def modules_tmp_path_prefix(modules_tmp_path_arg, monkeypatch_): + monkeypatch_.setattr(sys, "prefix", os.fspath(modules_tmp_path_arg)) + return modules_tmp_path_arg @pytest.fixture -def site_packages(modules_tmp_path, monkeypatch): +def site_packages(modules_tmp_path_local, monkeypatch_arg): """Create a fake site-packages.""" py_dir = f"python{sys.version_info.major}.{sys.version_info.minor}" - rv = modules_tmp_path / "lib" / py_dir / "site-packages" + rv = modules_tmp_path_local / "lib" / py_dir / "site-packages" rv.mkdir(parents=True) - monkeypatch.syspath_prepend(os.fspath(rv)) + monkeypatch_arg.syspath_prepend(os.fspath(rv)) return rv diff --git a/tests/test_appctx.py b/tests/test_appctx.py index ca9e079e..491dec67 100644 --- a/tests/test_appctx.py +++ b/tests/test_appctx.py @@ -131,7 +131,7 @@ def test_app_tearing_down_with_unhandled_exception(app, client): assert str(cleanup_stuff[0]) == "dummy" -def test_app_ctx_globals_methods(app, app_ctx): +def test_app_ctx_globals_methods(app, app_ctx_local): # get assert flask.g.get("foo") is None assert flask.g.get("foo", "bar") == "bar" diff --git a/tests/test_cli.py b/tests/test_cli.py index 09995488..7fa0f0e3 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -294,9 +294,9 @@ def test_app_cli_has_app_context(app, runner): @app.cli.command() @click.argument("value", callback=_param_cb) def check(value): - app = click.get_current_context().obj.load_app() + app_obj = click.get_current_context().obj.load_app() # the loaded app should be the same as current_app - same_app = current_app._get_current_object() is app + same_app = current_app._get_current_object() is app_obj return same_app, value cli = FlaskGroup(create_app=lambda: app) @@ -304,7 +304,7 @@ def test_app_cli_has_app_context(app, runner): assert result.return_value == (True, True) -def test_with_appcontext(runner): +def test_with_appcontext(runner_): @click.command() @with_appcontext def testcmd(): @@ -312,12 +312,12 @@ def test_with_appcontext(runner): obj = ScriptInfo(create_app=lambda: Flask("testapp")) - result = runner.invoke(testcmd, obj=obj) + result = runner_.invoke(testcmd, obj=obj) assert result.exit_code == 0 assert result.output == "testapp\n" -def test_appgroup_app_context(runner): +def test_appgroup_app_context(cli_runner): @click.group(cls=AppGroup) def cli(): pass @@ -336,16 +336,16 @@ def test_appgroup_app_context(runner): obj = ScriptInfo(create_app=lambda: Flask("testappgroup")) - result = runner.invoke(cli, ["test"], obj=obj) + result = cli_runner.invoke(cli, ["test"], obj=obj) assert result.exit_code == 0 assert result.output == "testappgroup\n" - result = runner.invoke(cli, ["subgroup", "test2"], obj=obj) + result = cli_runner.invoke(cli, ["subgroup", "test2"], obj=obj) assert result.exit_code == 0 assert result.output == "testappgroup\n" -def test_flaskgroup_app_context(runner): +def test_flaskgroup_app_context(runner_): def create_app(): return Flask("flaskgroup") @@ -357,7 +357,7 @@ def test_flaskgroup_app_context(runner): def test(): click.echo(current_app.name) - result = runner.invoke(cli, ["test"]) + result = runner_.invoke(cli, ["test"]) assert result.exit_code == 0 assert result.output == "flaskgroup\n" @@ -370,14 +370,14 @@ def test_flaskgroup_debug(runner, set_debug_flag): return app @click.group(cls=FlaskGroup, create_app=create_app, set_debug_flag=set_debug_flag) - def cli(**params): + def cli_command(**params): pass - @cli.command() + @cli_command.command() def test(): click.echo(str(current_app.debug)) - result = runner.invoke(cli, ["test"]) + result = runner.invoke(cli_command, ["test"]) assert result.exit_code == 0 assert result.output == f"{not set_debug_flag}\n" @@ -388,18 +388,18 @@ def test_flaskgroup_nested(app, runner): cli.add_command(flask_group) @flask_group.command() - def show(): + def show_command(): click.echo(current_app.name) - result = runner.invoke(cli, ["flask", "show"]) + result = runner.invoke(cli, ["flask", "show_command"]) assert result.output == "flask_test\n" def test_no_command_echo_loading_error(): from flask.cli import cli - runner = CliRunner(mix_stderr=False) - result = runner.invoke(cli, ["missing"]) + cli_runner = CliRunner(mix_stderr=False) + result = cli_runner.invoke(cli, ["missing"]) assert result.exit_code == 2 assert "FLASK_APP" in result.stderr assert "Usage:" in result.stderr @@ -408,8 +408,8 @@ def test_no_command_echo_loading_error(): def test_help_echo_loading_error(): from flask.cli import cli - runner = CliRunner(mix_stderr=False) - result = runner.invoke(cli, ["--help"]) + cli_runner = CliRunner(mix_stderr=False) + result = cli_runner.invoke(cli, ["--help"]) assert result.exit_code == 0 assert "FLASK_APP" in result.stderr assert "Usage:" in result.stdout @@ -420,8 +420,8 @@ def test_help_echo_exception(): raise Exception("oh no") cli = FlaskGroup(create_app=create_app) - runner = CliRunner(mix_stderr=False) - result = runner.invoke(cli, ["--help"]) + runner_obj = CliRunner(mix_stderr=False) + result = runner_obj.invoke(cli, ["--help"]) assert result.exit_code == 0 assert "Exception: oh no" in result.stderr assert "Usage:" in result.stdout @@ -476,30 +476,30 @@ class TestRoutes: output = invoke(["routes", "--all-methods"]).output assert "GET, HEAD, OPTIONS, POST" in output - def test_no_routes(self, runner): + def test_no_routes(self, runner_): app = Flask(__name__, static_folder=None) cli = FlaskGroup(create_app=lambda: app) - result = runner.invoke(cli, ["routes"]) + result = runner_.invoke(cli, ["routes"]) assert result.exit_code == 0 assert "No routes were registered." in result.output - def test_subdomain(self, runner): - app = Flask(__name__, static_folder=None) - app.add_url_rule("/a", subdomain="a", endpoint="a") - app.add_url_rule("/b", subdomain="b", endpoint="b") - cli = FlaskGroup(create_app=lambda: app) - result = runner.invoke(cli, ["routes"]) - assert result.exit_code == 0 - assert "Subdomain" in result.output + def test_subdomain(self, runner_): + app = Flask(__name__, static_folder=None) + app.add_url_rule("/a", subdomain="a", endpoint="a") + app.add_url_rule("/b", subdomain="b", endpoint="b") + cli = FlaskGroup(create_app=lambda: app) + result = runner_.invoke(cli, ["routes"]) + assert result.exit_code == 0 + assert "Subdomain" in result.output - def test_host(self, runner): - app = Flask(__name__, static_folder=None, host_matching=True) - app.add_url_rule("/a", host="a", endpoint="a") - app.add_url_rule("/b", host="b", endpoint="b") - cli = FlaskGroup(create_app=lambda: app) - result = runner.invoke(cli, ["routes"]) - assert result.exit_code == 0 - assert "Host" in result.output + def test_host(self, runner_): + app = Flask(__name__, static_folder=None, host_matching=True) + app.add_url_rule("/a", host="a", endpoint="a") + app.add_url_rule("/b", host="b", endpoint="b") + cli = FlaskGroup(create_app=lambda: app) + result = runner_.invoke(cli, ["routes"]) + assert result.exit_code == 0 + assert "Host" in result.output def dotenv_not_available(): @@ -558,10 +558,10 @@ def test_dotenv_optional(monkeypatch): @need_dotenv -def test_disable_dotenv_from_env(monkeypatch, runner): +def test_disable_dotenv_from_env(monkeypatch, runner_): monkeypatch.chdir(test_path) monkeypatch.setitem(os.environ, "FLASK_SKIP_DOTENV", "1") - runner.invoke(FlaskGroup()) + runner_.invoke(FlaskGroup()) assert "FOO" not in os.environ diff --git a/tests/test_json.py b/tests/test_json.py index 1e2b27dc..65c1f06c 100644 --- a/tests/test_json.py +++ b/tests/test_json.py @@ -196,8 +196,8 @@ def test_json_decimal(): def test_json_attr(app, client): @app.route("/add", methods=["POST"]) def add(): - json = flask.request.get_json() - return str(json["a"] + json["b"]) + data = flask.request.get_json() + return str(data["a"] + data["b"]) rv = client.post( "/add",