Skip to content
Myr

Merge pull request #1544 from pallets/remove-deprecated-code

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

remove deprecated code

authored by David Lord · committed by GitHub · parents a42b291, 8e98026 · Browse files · 10 files+27 added−274 removed
This commit

State

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

Diff stats

10 files+27 added−274 removed

  • tests:+0 added−17 removed
  • other:+27 added−257 removed

10 files+27 added−274 removed

modified:docs/api.rst-12 removed
595 unmodified lines
596.. autofunction:: jinja2.pass_eval_context597598.. autofunction:: jinja2.pass_environment599600.. autofunction:: jinja2.contextfilter601602.. autofunction:: jinja2.evalcontextfilter603604.. autofunction:: jinja2.environmentfilter605606.. autofunction:: jinja2.contextfunction607608.. autofunction:: jinja2.evalcontextfunction609610.. autofunction:: jinja2.environmentfunction611600.. autofunction:: jinja2.clear_caches601602.. autofunction:: jinja2.is_undefined603
316 unmodified lines
modified:requirements/dev.txt+6 added-6 removed
8 unmodified lines
9attrs==21.2.010 # via pytest11babel==2.9.112 # via sphinx13backports.entry-points-selectable==1.1.013backports.entry-points-selectable==1.1.114 # via virtualenv15certifi==2021.10.816 # via requests17cfgv==3.3.1
9 unmodified lines
27filelock==3.3.228 # via29 # tox30 # virtualenv31identify==2.3.331identify==2.3.532 # via pre-commit33idna==3.334 # via requests35imagesize==1.2.035imagesize==1.3.036 # via sphinx37iniconfig==1.1.138 # via pytest39jinja2==3.0.239jinja2==3.0.340 # via sphinx41markupsafe==2.0.142 # via jinja243mypy==0.910
7 unmodified lines
51 # pallets-sphinx-themes52 # pytest53 # sphinx54 # tox55pallets-sphinx-themes==2.0.155pallets-sphinx-themes==2.0.256 # via -r requirements/docs.in57pep517==0.12.058 # via pip-tools59pip-tools==6.4.0
27 unmodified lines
87 # tox88 # virtualenv89snowballstemmer==2.1.090 # via sphinx91sphinx==4.2.091sphinx==4.3.092 # via93 # -r requirements/docs.in94 # pallets-sphinx-themes95 # sphinx-issues
41 unmodified lines
modified:requirements/docs.txt+4 added-4 removed
14 unmodified lines
15docutils==0.17.116 # via sphinx17idna==3.318 # via requests19imagesize==1.2.019imagesize==1.3.020 # via sphinx21jinja2==3.0.221jinja2==3.0.322 # via sphinx23markupsafe==2.0.124 # via jinja225packaging==21.226 # via27 # pallets-sphinx-themes28 # sphinx29pallets-sphinx-themes==2.0.129pallets-sphinx-themes==2.0.230 # via -r requirements/docs.in31pygments==2.10.032 # via sphinx33pyparsing==2.4.7
3 unmodified lines
37requests==2.26.038 # via sphinx39snowballstemmer==2.1.040 # via sphinx41sphinx==4.2.041sphinx==4.3.042 # via43 # -r requirements/docs.in44 # pallets-sphinx-themes45 # sphinx-issues
22 unmodified lines
modified:src/jinja2/__init__.py-8 removed
12 unmodified lines
13from .exceptions import TemplateRuntimeError as TemplateRuntimeError14from .exceptions import TemplatesNotFound as TemplatesNotFound15from .exceptions import TemplateSyntaxError as TemplateSyntaxError16from .exceptions import UndefinedError as UndefinedError17from .filters import contextfilter18from .filters import environmentfilter19from .filters import evalcontextfilter17from .loaders import BaseLoader as BaseLoader18from .loaders import ChoiceLoader as ChoiceLoader19from .loaders import DictLoader as DictLoader20from .loaders import FileSystemLoader as FileSystemLoader
6 unmodified lines
27from .runtime import make_logging_undefined as make_logging_undefined28from .runtime import StrictUndefined as StrictUndefined29from .runtime import Undefined as Undefined30from .utils import clear_caches as clear_caches34from .utils import contextfunction35from .utils import environmentfunction36from .utils import escape37from .utils import evalcontextfunction31from .utils import is_undefined as is_undefined39from .utils import Markup32from .utils import pass_context as pass_context33from .utils import pass_environment as pass_environment34from .utils import pass_eval_context as pass_eval_context35from .utils import select_autoescape as select_autoescape
2 unmodified lines
modified:src/jinja2/ext.py-25 removed
1"""Extension API for adding custom tags and behavior."""2import pprint3import re4import typing as t5import warnings56from markupsafe import Markup78from . import defaults
586 unmodified lines
595 return nodes.Break(lineno=token.lineno)596 return nodes.Continue(lineno=token.lineno)597598600class WithExtension(Extension):601 def __init__(self, environment: Environment) -> None:602 super().__init__(environment)603 warnings.warn(604 "The 'with' extension is deprecated and will be removed in"605 " Jinja 3.1. This is built in now.",606 DeprecationWarning,607 stacklevel=3,608 )609610611class AutoEscapeExtension(Extension):612 def __init__(self, environment: Environment) -> None:613 super().__init__(environment)614 warnings.warn(615 "The 'autoescape' extension is deprecated and will be"616 " removed in Jinja 3.1. This is built in now.",617 DeprecationWarning,618 stacklevel=3,619 )620621599class DebugExtension(Extension):600 """A ``{% debug %}`` tag that dumps the available variables,601 filters, and tests.602
247 unmodified lines
850#: nicer import names851i18n = InternationalizationExtension852do = ExprStmtExtension853loopcontrols = LoopControlExtension877with_ = WithExtension878autoescape = AutoEscapeExtension854debug = DebugExtension
modified:src/jinja2/filters.py-53 removed
2 unmodified lines
3import random4import re5import typing6import typing as t7import warnings7from collections import abc8from itertools import chain9from itertools import groupby10
31 unmodified lines
42K = t.TypeVar("K")43V = t.TypeVar("V")444547def contextfilter(f: F) -> F:48 """Pass the context as the first argument to the decorated function.4950 .. deprecated:: 3.051 Will be removed in Jinja 3.1. Use :func:`~jinja2.pass_context`52 instead.53 """54 warnings.warn(55 "'contextfilter' is renamed to 'pass_context', the old name"56 " will be removed in Jinja 3.1.",57 DeprecationWarning,58 stacklevel=2,59 )60 return pass_context(f)616263def evalcontextfilter(f: F) -> F:64 """Pass the eval context as the first argument to the decorated65 function.6667 .. deprecated:: 3.068 Will be removed in Jinja 3.1. Use69 :func:`~jinja2.pass_eval_context` instead.7071 .. versionadded:: 2.472 """73 warnings.warn(74 "'evalcontextfilter' is renamed to 'pass_eval_context', the old"75 " name will be removed in Jinja 3.1.",76 DeprecationWarning,77 stacklevel=2,78 )79 return pass_eval_context(f)808182def environmentfilter(f: F) -> F:83 """Pass the environment as the first argument to the decorated84 function.8586 .. deprecated:: 3.087 Will be removed in Jinja 3.1. Use88 :func:`~jinja2.pass_environment` instead.89 """90 warnings.warn(91 "'environmentfilter' is renamed to 'pass_environment', the old"92 " name will be removed in Jinja 3.1.",93 DeprecationWarning,94 stacklevel=2,95 )96 return pass_environment(f)979846def ignore_case(value: V) -> V:47 """For use as a postprocessor for :func:`make_attrgetter`. Converts strings48 to lowercase and returns other types as-is."""49 if isinstance(value, str):
1722 unmodified lines
modified:src/jinja2/runtime.py-50 removed
87 unmodified lines
88 """Simple args to string conversion and concatenation."""89 return concat(map(str, seq))909192def unicode_join(seq: t.Iterable[t.Any]) -> str:93 import warnings9495 warnings.warn(96 "This template must be recompiled with at least Jinja 3.0, or"97 " it will fail in Jinja 3.1.",98 DeprecationWarning,99 stacklevel=2,100 )101 return str_join(seq)10210392def new_context(93 environment: "Environment",94 template_name: t.Optional[str],95 blocks: t.Dict[str, t.Callable[["Context"], t.Iterator[str]]],
64 unmodified lines
160 method that doesn't fail with a `KeyError` but returns an161 :class:`Undefined` object for missing variables.162 """163176 _legacy_resolve_mode: t.ClassVar[bool] = False177178 def __init_subclass__(cls) -> None:179 if "resolve_or_missing" in cls.__dict__:180 # If the subclass overrides resolve_or_missing it opts in to181 # modern mode no matter what.182 cls._legacy_resolve_mode = False183 elif "resolve" in cls.__dict__ or cls._legacy_resolve_mode:184 # If the subclass overrides resolve, or if its base is185 # already in legacy mode, warn about legacy behavior.186 import warnings187188 warnings.warn(189 "Overriding 'resolve' is deprecated and will not have"190 " the expected behavior in Jinja 3.1. Override"191 " 'resolve_or_missing' instead ",192 DeprecationWarning,193 stacklevel=2,194 )195 cls._legacy_resolve_mode = True196164 def __init__(165 self,166 environment: "Environment",167 parent: t.Dict[str, t.Any],
49 unmodified lines
217 functions use that method, not this one.218219 :param key: The variable name to look up.220 """254 if self._legacy_resolve_mode:255 if key in self.vars:256 return self.vars[key]257258 if key in self.parent:259 return self.parent[key]260261 return self.environment.undefined(name=key)262221 rv = self.resolve_or_missing(key)222223 if rv is missing:224 return self.environment.undefined(name=key)
9 unmodified lines
234 method. Don't call this method directly.235236 :param key: The variable name to look up.237 """280 if self._legacy_resolve_mode:281 rv = self.resolve(key)282283 if isinstance(rv, Undefined):284 return missing285286 return rv287238 if key in self.vars:239 return self.vars[key]240241 if key in self.parent:
813 unmodified lines
modified:src/jinja2/utils.py-99 removed
1 unmodified line
2import json3import os4import re5import typing as t6import warnings6from collections import abc7from collections import deque8from random import choice9from random import randrange
72 unmodified lines
82 def from_obj(cls, obj: F) -> t.Optional["_PassArg"]:83 if hasattr(obj, "jinja_pass_arg"):84 return obj.jinja_pass_arg # type: ignore8587 for prefix in "context", "eval_context", "environment":88 squashed = prefix.replace("_", "")8990 for name in f"{squashed}function", f"{squashed}filter":91 if getattr(obj, name, False) is True:92 warnings.warn(93 f"{name!r} is deprecated and will stop working"94 f" in Jinja 3.1. Use 'pass_{prefix}' instead.",95 DeprecationWarning,96 stacklevel=2,97 )98 return cls[prefix]9986 return None8788103def contextfunction(f: F) -> F:104 """Pass the context as the first argument to the decorated function.105106 .. deprecated:: 3.0107 Will be removed in Jinja 3.1. Use :func:`~jinja2.pass_context`108 instead.109 """110 warnings.warn(111 "'contextfunction' is renamed to 'pass_context', the old name"112 " will be removed in Jinja 3.1.",113 DeprecationWarning,114 stacklevel=2,115 )116 return pass_context(f)117118119def evalcontextfunction(f: F) -> F:120 """Pass the eval context as the first argument to the decorated121 function.122123 .. deprecated:: 3.0124 Will be removed in Jinja 3.1. Use125 :func:`~jinja2.pass_eval_context` instead.126127 .. versionadded:: 2.4128 """129 warnings.warn(130 "'evalcontextfunction' is renamed to 'pass_eval_context', the"131 " old name will be removed in Jinja 3.1.",132 DeprecationWarning,133 stacklevel=2,134 )135 return pass_eval_context(f)136137138def environmentfunction(f: F) -> F:139 """Pass the environment as the first argument to the decorated140 function.141142 .. deprecated:: 3.0143 Will be removed in Jinja 3.1. Use144 :func:`~jinja2.pass_environment` instead.145 """146 warnings.warn(147 "'environmentfunction' is renamed to 'pass_environment', the"148 " old name will be removed in Jinja 3.1.",149 DeprecationWarning,150 stacklevel=2,151 )152 return pass_environment(f)15315489def internalcode(f: F) -> F:90 """Marks the function as internally used"""91 internal_code.add(f.__code__)92 return f
323 unmodified lines
416417 return rv418419486def unicode_urlencode(obj: t.Any, charset: str = "utf-8", for_qs: bool = False) -> str:487 import warnings488489 warnings.warn(490 "'unicode_urlencode' has been renamed to 'url_quote'. The old"491 " name will be removed in Jinja 3.1.",492 DeprecationWarning,493 stacklevel=2,494 )495 return url_quote(obj, charset=charset, for_qs=for_qs)496497420@abc.MutableMapping.register421class LRUCache:422 """A simple LRU Cache implementation."""423
328 unmodified lines
752 self.__attrs[name] = value753754 def __repr__(self) -> str:755 return f"<Namespace {self.__attrs!r}>"834835836class Markup(markupsafe.Markup):837 def __new__(cls, base="", encoding=None, errors="strict"): # type: ignore838 warnings.warn(839 "'jinja2.Markup' is deprecated and will be removed in Jinja"840 " 3.1. Import 'markupsafe.Markup' instead.",841 DeprecationWarning,842 stacklevel=2,843 )844 return super().__new__(cls, base, encoding, errors)845846847def escape(s: t.Any) -> str:848 warnings.warn(849 "'jinja2.escape' is deprecated and will be removed in Jinja"850 " 3.1. Import 'markupsafe.escape' instead.",851 DeprecationWarning,852 stacklevel=2,853 )854 return markupsafe.escape(s)
modified:tests/test_regression.py-17 removed
589 unmodified lines
590 loader = DictLoader({"base": "{{ foobar }}", "test": '{% extends "base" %}'})591 env = MyEnvironment(loader=loader)592 assert env.get_template("test").render(foobar="test") == "test"593594 def test_legacy_custom_context(self, env):595 from jinja2.runtime import Context, missing596597 with pytest.deprecated_call():598599 class MyContext(Context):600 def resolve(self, name):601 if name == "foo":602 return 42603 return super().resolve(name)604605 x = MyContext(env, parent={"bar": 23}, name="foo", blocks={})606 assert x._legacy_resolve_mode607 assert x.resolve_or_missing("foo") == 42608 assert x.resolve_or_missing("bar") == 23609 assert x.resolve_or_missing("baz") is missing610594 def test_recursive_loop_bug(self, env):595 tmpl = env.from_string(596 "{%- for value in values recursive %}1{% else %}0{% endfor -%}"597 )
147 unmodified lines
modified:CHANGES.rst+17 added
3 unmodified lines
4-------------56Unreleased78- Drop support for Python 3.6. :pr:`1534`9- Remove previously deprecated code. :pr:`1544`1011 - ``WithExtension`` and ``AutoEscapeExtension`` are built-in now.12 - ``contextfilter`` and ``contextfunction`` are replaced by13 ``pass_context``. ``evalcontextfilter`` and14 ``evalcontextfunction`` are replaced by ``pass_eval_context``.15 ``environmentfilter`` and ``environmentfunction`` are replaced16 by ``pass_environment``.17 - ``Markup`` and ``escape`` should be imported from MarkupSafe.18 - Compiled templates from very old Jinja versions may need to be19 recompiled.20 - Legacy resolve mode for ``Context`` subclasses is no longer21 supported. Override ``resolve_or_missing`` instead of22 ``resolve``.23 - ``unicode_urlencode`` is renamed to ``url_quote``.242526Version 3.0.327-------------2829Released 2021-11-09
909 unmodified lines