Skip to content

Commit

Permalink
warn about env_options usage
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-oleshkevich committed Jun 1, 2023
1 parent 39ee96e commit 7c9f4fc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions starlette/templating.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import typing
import warnings
from os import PathLike

from starlette.background import BackgroundTask
Expand Down Expand Up @@ -71,6 +72,11 @@ def __init__(
env: typing.Optional[jinja2.Environment] = None,
**env_options: typing.Any,
) -> None:
if env_options:
warnings.warn(
"Extra environment options are deprecated. Use a preconfigured jinja2.Environment instead.", # noqa: E501
DeprecationWarning,
)
assert jinja2 is not None, "jinja2 must be installed to use Jinja2Templates"
assert directory or env, "either 'directory' or 'env' arguments must be passed"
self.context_processors = context_processors or []
Expand Down
5 changes: 5 additions & 0 deletions tests/test_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,8 @@ def test_templates_with_environment(tmpdir):
templates = Jinja2Templates(env=env)
template = templates.get_template("index.html")
assert template.render({}) == "Hello"


def test_templates_with_environment_options_emit_warning(tmpdir):
with pytest.warns(DeprecationWarning):
Jinja2Templates(str(tmpdir), autoescape=True)

0 comments on commit 7c9f4fc

Please sign in to comment.