Skip to content
Closed

AI junk #6078

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/flask/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,18 @@ def show_server_banner(debug: bool, app_import_path: str | None) -> None:
click.echo(f" * Debug mode: {'on' if debug else 'off'}")


class CertParamType(click.ParamType[t.Any]):
if t.TYPE_CHECKING:

class _CertParamTypeBase(click.ParamType[t.Any]):
pass

else:

class _CertParamTypeBase(click.ParamType):
pass


class CertParamType(_CertParamTypeBase):
"""Click option type for the ``--cert`` option. Allows either an
existing file, the string ``'adhoc'``, or an import for a
:class:`~ssl.SSLContext` object.
Expand Down
16 changes: 10 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
from flask import Flask
from flask.globals import app_ctx as _app_ctx

_MONKEYPATCH_NOTSET = (
monkeypatch.NOTSET if hasattr(monkeypatch, "NOTSET") else monkeypatch.notset
)


@pytest.fixture(scope="session", autouse=True)
def _standard_os_environ():
Expand All @@ -16,15 +20,15 @@ def _standard_os_environ():
"""
mp = monkeypatch.MonkeyPatch()
out = (
(os.environ, "FLASK_ENV_FILE", monkeypatch.notset),
(os.environ, "FLASK_APP", monkeypatch.notset),
(os.environ, "FLASK_DEBUG", monkeypatch.notset),
(os.environ, "FLASK_RUN_FROM_CLI", monkeypatch.notset),
(os.environ, "WERKZEUG_RUN_MAIN", monkeypatch.notset),
(os.environ, "FLASK_ENV_FILE", _MONKEYPATCH_NOTSET),
(os.environ, "FLASK_APP", _MONKEYPATCH_NOTSET),
(os.environ, "FLASK_DEBUG", _MONKEYPATCH_NOTSET),
(os.environ, "FLASK_RUN_FROM_CLI", _MONKEYPATCH_NOTSET),
(os.environ, "WERKZEUG_RUN_MAIN", _MONKEYPATCH_NOTSET),
)

for _, key, value in out:
if value is monkeypatch.notset:
if value is _MONKEYPATCH_NOTSET:
mp.delenv(key, False)
else:
mp.setenv(key, value)
Expand Down
7 changes: 6 additions & 1 deletion tests/test_blueprints.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import pytest
from jinja2 import TemplateNotFound
from werkzeug.http import parse_cache_control_header
from werkzeug.datastructures.cache_control import ResponseCacheControl

if hasattr(ResponseCacheControl, "from_header"):
parse_cache_control_header = ResponseCacheControl.from_header
else:
from werkzeug.http import parse_cache_control_header

import flask

Expand Down
11 changes: 8 additions & 3 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import click
import pytest
from _pytest.monkeypatch import notset
from _pytest import monkeypatch as _pytest_monkeypatch
from click.testing import CliRunner

from flask import Blueprint
Expand All @@ -31,6 +31,11 @@

cwd = Path.cwd()
test_path = (Path(__file__) / ".." / "test_apps").resolve()
_MONKEYPATCH_NOTSET = (
_pytest_monkeypatch.NOTSET
if hasattr(_pytest_monkeypatch, "NOTSET")
else _pytest_monkeypatch.notset
)


@pytest.fixture
Expand Down Expand Up @@ -537,7 +542,7 @@ def dotenv_not_available():
def test_load_dotenv(monkeypatch):
# can't use monkeypatch.delitem since the keys don't exist yet
for item in ("FOO", "BAR", "SPAM", "HAM"):
monkeypatch._setitem.append((os.environ, item, notset))
monkeypatch._setitem.append((os.environ, item, _MONKEYPATCH_NOTSET))

monkeypatch.setenv("EGGS", "3")
monkeypatch.chdir(test_path)
Expand All @@ -560,7 +565,7 @@ def test_load_dotenv(monkeypatch):
@need_dotenv
def test_dotenv_path(monkeypatch):
for item in ("FOO", "BAR", "EGGS"):
monkeypatch._setitem.append((os.environ, item, notset))
monkeypatch._setitem.append((os.environ, item, _MONKEYPATCH_NOTSET))

load_dotenv(test_path / ".flaskenv")
assert Path.cwd() == cwd
Expand Down
7 changes: 6 additions & 1 deletion tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import pytest
from werkzeug.http import parse_set_header
from werkzeug.datastructures import HeaderSet

if hasattr(HeaderSet, "from_header"):
parse_set_header = HeaderSet.from_header
else:
from werkzeug.http import parse_set_header

import flask.views
from flask.testing import FlaskClient
Expand Down
Loading