Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove deprecated code #1544

Merged
merged 7 commits into from
Nov 10, 2021
Merged
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
17 changes: 17 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,23 @@ Version 3.1.0

Unreleased

- Drop support for Python 3.6. :pr:`1534`
- Remove previously deprecated code. :pr:`1544`

- ``WithExtension`` and ``AutoEscapeExtension`` are built-in now.
- ``contextfilter`` and ``contextfunction`` are replaced by
``pass_context``. ``evalcontextfilter`` and
``evalcontextfunction`` are replaced by ``pass_eval_context``.
``environmentfilter`` and ``environmentfunction`` are replaced
by ``pass_environment``.
- ``Markup`` and ``escape`` should be imported from MarkupSafe.
- Compiled templates from very old Jinja versions may need to be
recompiled.
- Legacy resolve mode for ``Context`` subclasses is no longer
supported. Override ``resolve_or_missing`` instead of
``resolve``.
- ``unicode_urlencode`` is renamed to ``url_quote``.


Version 3.0.3
-------------
Expand Down
12 changes: 0 additions & 12 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -597,18 +597,6 @@ functions to a Jinja environment.

.. autofunction:: jinja2.pass_environment

.. autofunction:: jinja2.contextfilter

.. autofunction:: jinja2.evalcontextfilter

.. autofunction:: jinja2.environmentfilter

.. autofunction:: jinja2.contextfunction

.. autofunction:: jinja2.evalcontextfunction

.. autofunction:: jinja2.environmentfunction

.. autofunction:: jinja2.clear_caches

.. autofunction:: jinja2.is_undefined
Expand Down
12 changes: 6 additions & 6 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ attrs==21.2.0
# via pytest
babel==2.9.1
# via sphinx
backports.entry-points-selectable==1.1.0
backports.entry-points-selectable==1.1.1
# via virtualenv
certifi==2021.10.8
# via requests
Expand All @@ -28,15 +28,15 @@ filelock==3.3.2
# via
# tox
# virtualenv
identify==2.3.3
identify==2.3.5
# via pre-commit
idna==3.3
# via requests
imagesize==1.2.0
imagesize==1.3.0
# via sphinx
iniconfig==1.1.1
# via pytest
jinja2==3.0.2
jinja2==3.0.3
# via sphinx
markupsafe==2.0.1
# via jinja2
Expand All @@ -52,7 +52,7 @@ packaging==21.2
# pytest
# sphinx
# tox
pallets-sphinx-themes==2.0.1
pallets-sphinx-themes==2.0.2
# via -r requirements/docs.in
pep517==0.12.0
# via pip-tools
Expand Down Expand Up @@ -88,7 +88,7 @@ six==1.16.0
# virtualenv
snowballstemmer==2.1.0
# via sphinx
sphinx==4.2.0
sphinx==4.3.0
# via
# -r requirements/docs.in
# pallets-sphinx-themes
Expand Down
8 changes: 4 additions & 4 deletions requirements/docs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ docutils==0.17.1
# via sphinx
idna==3.3
# via requests
imagesize==1.2.0
imagesize==1.3.0
# via sphinx
jinja2==3.0.2
jinja2==3.0.3
# via sphinx
markupsafe==2.0.1
# via jinja2
packaging==21.2
# via
# pallets-sphinx-themes
# sphinx
pallets-sphinx-themes==2.0.1
pallets-sphinx-themes==2.0.2
# via -r requirements/docs.in
pygments==2.10.0
# via sphinx
Expand All @@ -38,7 +38,7 @@ requests==2.26.0
# via sphinx
snowballstemmer==2.1.0
# via sphinx
sphinx==4.2.0
sphinx==4.3.0
# via
# -r requirements/docs.in
# pallets-sphinx-themes
Expand Down
8 changes: 0 additions & 8 deletions src/jinja2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
from .exceptions import TemplatesNotFound as TemplatesNotFound
from .exceptions import TemplateSyntaxError as TemplateSyntaxError
from .exceptions import UndefinedError as UndefinedError
from .filters import contextfilter
from .filters import environmentfilter
from .filters import evalcontextfilter
from .loaders import BaseLoader as BaseLoader
from .loaders import ChoiceLoader as ChoiceLoader
from .loaders import DictLoader as DictLoader
Expand All @@ -31,12 +28,7 @@
from .runtime import StrictUndefined as StrictUndefined
from .runtime import Undefined as Undefined
from .utils import clear_caches as clear_caches
from .utils import contextfunction
from .utils import environmentfunction
from .utils import escape
from .utils import evalcontextfunction
from .utils import is_undefined as is_undefined
from .utils import Markup
from .utils import pass_context as pass_context
from .utils import pass_environment as pass_environment
from .utils import pass_eval_context as pass_eval_context
Expand Down
25 changes: 0 additions & 25 deletions src/jinja2/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import pprint
import re
import typing as t
import warnings

from markupsafe import Markup

Expand Down Expand Up @@ -597,28 +596,6 @@ def parse(self, parser: "Parser") -> t.Union[nodes.Break, nodes.Continue]:
return nodes.Continue(lineno=token.lineno)


class WithExtension(Extension):
def __init__(self, environment: Environment) -> None:
super().__init__(environment)
warnings.warn(
"The 'with' extension is deprecated and will be removed in"
" Jinja 3.1. This is built in now.",
DeprecationWarning,
stacklevel=3,
)


class AutoEscapeExtension(Extension):
def __init__(self, environment: Environment) -> None:
super().__init__(environment)
warnings.warn(
"The 'autoescape' extension is deprecated and will be"
" removed in Jinja 3.1. This is built in now.",
DeprecationWarning,
stacklevel=3,
)


class DebugExtension(Extension):
"""A ``{% debug %}`` tag that dumps the available variables,
filters, and tests.
Expand Down Expand Up @@ -874,6 +851,4 @@ def getbool(options: t.Mapping[str, str], key: str, default: bool = False) -> bo
i18n = InternationalizationExtension
do = ExprStmtExtension
loopcontrols = LoopControlExtension
with_ = WithExtension
autoescape = AutoEscapeExtension
debug = DebugExtension
53 changes: 0 additions & 53 deletions src/jinja2/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import re
import typing
import typing as t
import warnings
from collections import abc
from itertools import chain
from itertools import groupby
Expand Down Expand Up @@ -44,58 +43,6 @@ def __html__(self) -> str:
V = t.TypeVar("V")


def contextfilter(f: F) -> F:
"""Pass the context as the first argument to the decorated function.

.. deprecated:: 3.0
Will be removed in Jinja 3.1. Use :func:`~jinja2.pass_context`
instead.
"""
warnings.warn(
"'contextfilter' is renamed to 'pass_context', the old name"
" will be removed in Jinja 3.1.",
DeprecationWarning,
stacklevel=2,
)
return pass_context(f)


def evalcontextfilter(f: F) -> F:
"""Pass the eval context as the first argument to the decorated
function.

.. deprecated:: 3.0
Will be removed in Jinja 3.1. Use
:func:`~jinja2.pass_eval_context` instead.

.. versionadded:: 2.4
"""
warnings.warn(
"'evalcontextfilter' is renamed to 'pass_eval_context', the old"
" name will be removed in Jinja 3.1.",
DeprecationWarning,
stacklevel=2,
)
return pass_eval_context(f)


def environmentfilter(f: F) -> F:
"""Pass the environment as the first argument to the decorated
function.

.. deprecated:: 3.0
Will be removed in Jinja 3.1. Use
:func:`~jinja2.pass_environment` instead.
"""
warnings.warn(
"'environmentfilter' is renamed to 'pass_environment', the old"
" name will be removed in Jinja 3.1.",
DeprecationWarning,
stacklevel=2,
)
return pass_environment(f)


def ignore_case(value: V) -> V:
"""For use as a postprocessor for :func:`make_attrgetter`. Converts strings
to lowercase and returns other types as-is."""
Expand Down
50 changes: 0 additions & 50 deletions src/jinja2/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,6 @@ def str_join(seq: t.Iterable[t.Any]) -> str:
return concat(map(str, seq))


def unicode_join(seq: t.Iterable[t.Any]) -> str:
import warnings

warnings.warn(
"This template must be recompiled with at least Jinja 3.0, or"
" it will fail in Jinja 3.1.",
DeprecationWarning,
stacklevel=2,
)
return str_join(seq)


def new_context(
environment: "Environment",
template_name: t.Optional[str],
Expand Down Expand Up @@ -173,27 +161,6 @@ class Context:
:class:`Undefined` object for missing variables.
"""

_legacy_resolve_mode: t.ClassVar[bool] = False

def __init_subclass__(cls) -> None:
if "resolve_or_missing" in cls.__dict__:
# If the subclass overrides resolve_or_missing it opts in to
# modern mode no matter what.
cls._legacy_resolve_mode = False
elif "resolve" in cls.__dict__ or cls._legacy_resolve_mode:
# If the subclass overrides resolve, or if its base is
# already in legacy mode, warn about legacy behavior.
import warnings

warnings.warn(
"Overriding 'resolve' is deprecated and will not have"
" the expected behavior in Jinja 3.1. Override"
" 'resolve_or_missing' instead ",
DeprecationWarning,
stacklevel=2,
)
cls._legacy_resolve_mode = True

def __init__(
self,
environment: "Environment",
Expand Down Expand Up @@ -251,15 +218,6 @@ def resolve(self, key: str) -> t.Union[t.Any, "Undefined"]:

:param key: The variable name to look up.
"""
if self._legacy_resolve_mode:
if key in self.vars:
return self.vars[key]

if key in self.parent:
return self.parent[key]

return self.environment.undefined(name=key)

rv = self.resolve_or_missing(key)

if rv is missing:
Expand All @@ -277,14 +235,6 @@ def resolve_or_missing(self, key: str) -> t.Any:

:param key: The variable name to look up.
"""
if self._legacy_resolve_mode:
rv = self.resolve(key)

if isinstance(rv, Undefined):
return missing

return rv

if key in self.vars:
return self.vars[key]

Expand Down
Loading