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
Provenance
- Commit
b285d0c- Tree
bc5a26b- Author
David Lord <davidism@gmail.com>- Committer
GitHub <noreply@github.com>- Parent 1
a42b291- Parent 2
8e98026
10 files changed+27 added−274 removed
modified:docs/api.rst-12 removed
595 unmodified lines596 .. autofunction:: jinja2.pass_eval_context597 598 .. autofunction:: jinja2.pass_environment599 600-.. autofunction:: jinja2.contextfilter601-602-.. autofunction:: jinja2.evalcontextfilter603-604-.. autofunction:: jinja2.environmentfilter605-606-.. autofunction:: jinja2.contextfunction607-608-.. autofunction:: jinja2.evalcontextfunction609-610-.. autofunction:: jinja2.environmentfunction611-600 .. autofunction:: jinja2.clear_caches601 602 .. autofunction:: jinja2.is_undefined603 316 unmodified linesmodified:requirements/dev.txt+6 added-6 removed
8 unmodified lines9 attrs==21.2.010 # via pytest11 babel==2.9.112 # via sphinx13-backports.entry-points-selectable==1.1.013+backports.entry-points-selectable==1.1.114 # via virtualenv15 certifi==2021.10.816 # via requests17 cfgv==3.3.19 unmodified lines27 filelock==3.3.228 # via29 # tox30 # virtualenv31-identify==2.3.331+identify==2.3.532 # via pre-commit33 idna==3.334 # via requests35-imagesize==1.2.035+imagesize==1.3.036 # via sphinx37 iniconfig==1.1.138 # via pytest39-jinja2==3.0.239+jinja2==3.0.340 # via sphinx41 markupsafe==2.0.142 # via jinja243 mypy==0.9107 unmodified lines51 # pallets-sphinx-themes52 # pytest53 # sphinx54 # tox55-pallets-sphinx-themes==2.0.155+pallets-sphinx-themes==2.0.256 # via -r requirements/docs.in57 pep517==0.12.058 # via pip-tools59 pip-tools==6.4.027 unmodified lines87 # tox88 # virtualenv89 snowballstemmer==2.1.090 # via sphinx91-sphinx==4.2.091+sphinx==4.3.092 # via93 # -r requirements/docs.in94 # pallets-sphinx-themes95 # sphinx-issues41 unmodified linesmodified:requirements/docs.txt+4 added-4 removed
14 unmodified lines15 docutils==0.17.116 # via sphinx17 idna==3.318 # via requests19-imagesize==1.2.019+imagesize==1.3.020 # via sphinx21-jinja2==3.0.221+jinja2==3.0.322 # via sphinx23 markupsafe==2.0.124 # via jinja225 packaging==21.226 # via27 # pallets-sphinx-themes28 # sphinx29-pallets-sphinx-themes==2.0.129+pallets-sphinx-themes==2.0.230 # via -r requirements/docs.in31 pygments==2.10.032 # via sphinx33 pyparsing==2.4.73 unmodified lines37 requests==2.26.038 # via sphinx39 snowballstemmer==2.1.040 # via sphinx41-sphinx==4.2.041+sphinx==4.3.042 # via43 # -r requirements/docs.in44 # pallets-sphinx-themes45 # sphinx-issues22 unmodified linesmodified:src/jinja2/__init__.py-8 removed
12 unmodified lines13 from .exceptions import TemplateRuntimeError as TemplateRuntimeError14 from .exceptions import TemplatesNotFound as TemplatesNotFound15 from .exceptions import TemplateSyntaxError as TemplateSyntaxError16 from .exceptions import UndefinedError as UndefinedError17-from .filters import contextfilter18-from .filters import environmentfilter19-from .filters import evalcontextfilter17 from .loaders import BaseLoader as BaseLoader18 from .loaders import ChoiceLoader as ChoiceLoader19 from .loaders import DictLoader as DictLoader20 from .loaders import FileSystemLoader as FileSystemLoader6 unmodified lines27 from .runtime import make_logging_undefined as make_logging_undefined28 from .runtime import StrictUndefined as StrictUndefined29 from .runtime import Undefined as Undefined30 from .utils import clear_caches as clear_caches34-from .utils import contextfunction35-from .utils import environmentfunction36-from .utils import escape37-from .utils import evalcontextfunction31 from .utils import is_undefined as is_undefined39-from .utils import Markup32 from .utils import pass_context as pass_context33 from .utils import pass_environment as pass_environment34 from .utils import pass_eval_context as pass_eval_context35 from .utils import select_autoescape as select_autoescape2 unmodified linesmodified:src/jinja2/ext.py-25 removed
1 """Extension API for adding custom tags and behavior."""2 import pprint3 import re4 import typing as t5-import warnings5 6 from markupsafe import Markup7 8 from . import defaults586 unmodified lines595 return nodes.Break(lineno=token.lineno)596 return nodes.Continue(lineno=token.lineno)597 598 600-class 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- )609-610-611-class 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- )620-621-599 class DebugExtension(Extension):600 """A ``{% debug %}`` tag that dumps the available variables,601 filters, and tests.602 247 unmodified lines850 #: nicer import names851 i18n = InternationalizationExtension852 do = ExprStmtExtension853 loopcontrols = LoopControlExtension877-with_ = WithExtension878-autoescape = AutoEscapeExtension854 debug = DebugExtensionmodified:src/jinja2/filters.py-53 removed
2 unmodified lines3 import random4 import re5 import typing6 import typing as t7-import warnings7 from collections import abc8 from itertools import chain9 from itertools import groupby10 31 unmodified lines42 K = t.TypeVar("K")43 V = t.TypeVar("V")44 45 47-def contextfilter(f: F) -> F:48- """Pass the context as the first argument to the decorated function.49-50- .. 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)61-62-63-def evalcontextfilter(f: F) -> F:64- """Pass the eval context as the first argument to the decorated65- function.66-67- .. deprecated:: 3.068- Will be removed in Jinja 3.1. Use69- :func:`~jinja2.pass_eval_context` instead.70-71- .. 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)80-81-82-def environmentfilter(f: F) -> F:83- """Pass the environment as the first argument to the decorated84- function.85-86- .. 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)97-98-46 def 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 linesmodified:src/jinja2/runtime.py-50 removed
87 unmodified lines88 """Simple args to string conversion and concatenation."""89 return concat(map(str, seq))90 91 92-def unicode_join(seq: t.Iterable[t.Any]) -> str:93- import warnings94-95- 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)102-103-92 def new_context(93 environment: "Environment",94 template_name: t.Optional[str],95 blocks: t.Dict[str, t.Callable[["Context"], t.Iterator[str]]],64 unmodified lines160 method that doesn't fail with a `KeyError` but returns an161 :class:`Undefined` object for missing variables.162 """163 176- _legacy_resolve_mode: t.ClassVar[bool] = False177-178- 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 warnings187-188- 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 = True196-164 def __init__(165 self,166 environment: "Environment",167 parent: t.Dict[str, t.Any],49 unmodified lines217 functions use that method, not this one.218 219 :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]257-258- if key in self.parent:259- return self.parent[key]260-261- return self.environment.undefined(name=key)262-221 rv = self.resolve_or_missing(key)222 223 if rv is missing:224 return self.environment.undefined(name=key)9 unmodified lines234 method. Don't call this method directly.235 236 :param key: The variable name to look up.237 """280- if self._legacy_resolve_mode:281- rv = self.resolve(key)282-283- if isinstance(rv, Undefined):284- return missing285-286- return rv287-238 if key in self.vars:239 return self.vars[key]240 241 if key in self.parent:813 unmodified linesmodified:src/jinja2/utils.py-99 removed
1 unmodified line2 import json3 import os4 import re5 import typing as t6-import warnings6 from collections import abc7 from collections import deque8 from random import choice9 from random import randrange72 unmodified lines82 def from_obj(cls, obj: F) -> t.Optional["_PassArg"]:83 if hasattr(obj, "jinja_pass_arg"):84 return obj.jinja_pass_arg # type: ignore85 87- for prefix in "context", "eval_context", "environment":88- squashed = prefix.replace("_", "")89-90- 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]99-86 return None87 88 103-def contextfunction(f: F) -> F:104- """Pass the context as the first argument to the decorated function.105-106- .. 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)117-118-119-def evalcontextfunction(f: F) -> F:120- """Pass the eval context as the first argument to the decorated121- function.122-123- .. deprecated:: 3.0124- Will be removed in Jinja 3.1. Use125- :func:`~jinja2.pass_eval_context` instead.126-127- .. 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)136-137-138-def environmentfunction(f: F) -> F:139- """Pass the environment as the first argument to the decorated140- function.141-142- .. 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)153-154-89 def internalcode(f: F) -> F:90 """Marks the function as internally used"""91 internal_code.add(f.__code__)92 return f323 unmodified lines416 417 return rv418 419 486-def unicode_urlencode(obj: t.Any, charset: str = "utf-8", for_qs: bool = False) -> str:487- import warnings488-489- 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)496-497-420 @abc.MutableMapping.register421 class LRUCache:422 """A simple LRU Cache implementation."""423 328 unmodified lines752 self.__attrs[name] = value753 754 def __repr__(self) -> str:755 return f"<Namespace {self.__attrs!r}>"834-835-836-class 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)845-846-847-def 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 lines590 loader = DictLoader({"base": "{{ foobar }}", "test": '{% extends "base" %}'})591 env = MyEnvironment(loader=loader)592 assert env.get_template("test").render(foobar="test") == "test"593 594- def test_legacy_custom_context(self, env):595- from jinja2.runtime import Context, missing596-597- with pytest.deprecated_call():598-599- class MyContext(Context):600- def resolve(self, name):601- if name == "foo":602- return 42603- return super().resolve(name)604-605- 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 missing610-594 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 linesmodified:CHANGES.rst+17 added
3 unmodified lines4 -------------5 6 Unreleased7 8+- Drop support for Python 3.6. :pr:`1534`9+- Remove previously deprecated code. :pr:`1544`10 11+ - ``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``.24+25+26 Version 3.0.327 -------------28 29 Released 2021-11-09909 unmodified lines