Merge branch '3.0.x'
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Lord · committed by David Lord · parents 647677d, fb9cac6 · Browse files · 14 files·+88 added−83 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
14 files+88 added−83 removed
- other:+88 added−83 removed
Provenance
- Commit
e20a52e- Tree
5fe430f- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent 1
647677d- Parent 2
fb9cac6
14 files changed+88 added−83 removed
modified:docs/extensions.rst+1 added-1 removed
121 unmodified lines122 The usage of the ``i18n`` extension for template designers is covered in123 :ref:`the template documentation <i18n-in-templates>`.124 125 .. _gettext: https://docs.python.org/3/library/gettext.html126-.. _Babel: http://babel.pocoo.org/126+.. _Babel: https://babel.pocoo.org/127 128 129 Whitespace Trimming130 ~~~~~~~~~~~~~~~~~~~293 unmodified linesmodified:docs/intro.rst+1 added-1 removed
58 unmodified lines59 These distributions will not be installed automatically.60 61 - `Babel`_ provides translation support in templates.62 63-.. _Babel: http://babel.pocoo.org/63+.. _Babel: https://babel.pocoo.org/modified:docs/make.bat+1 added-1 removed
19 unmodified lines20 echo.to the full path of the 'sphinx-build' executable. Alternatively you21 echo.may add the Sphinx directory to PATH.22 echo.23 echo.If you don't have Sphinx installed, grab it from24- echo.http://sphinx-doc.org/24+ echo.https://www.sphinx-doc.org/25 exit /b 126 )27 28 %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%7 unmodified linesmodified:requirements/dev.txt+33 added-30 removed
4 unmodified lines5 # pip-compile requirements/dev.in6 #7 alabaster==0.7.128 # via sphinx9-appdirs==1.4.410- # via virtualenv9 attrs==21.2.010 # via pytest11 babel==2.9.112 # via sphinx13+backports.entry-points-selectable==1.1.014+ # via virtualenv15-certifi==2020.12.515+certifi==2021.5.3016 # via requests17-cfgv==3.3.017+cfgv==3.3.118 # via pre-commit19-chardet==4.0.019+charset-normalizer==2.0.620 # via requests21 click==8.0.122 # via pip-tools23-distlib==0.3.123+distlib==0.3.324 # via virtualenv25 docutils==0.17.126 # via sphinx27-filelock==3.0.1227+filelock==3.3.028 # via29 # tox30 # virtualenv31-identify==2.2.431+identify==2.3.032 # via pre-commit33-idna==2.1033+idna==3.234 # via requests35 imagesize==1.2.036 # via sphinx37 iniconfig==1.1.11 unmodified line39 jinja2==3.0.140 # via sphinx41 markupsafe==2.0.142 # via jinja243-mypy==0.91044- # via -r requirements/typing.in43 mypy-extensions==0.4.344 # via mypy45+mypy==0.91046+ # via -r requirements/typing.in47 nodeenv==1.6.048 # via pre-commit49-packaging==20.949+packaging==21.050 # via51 # pallets-sphinx-themes52 # pytest53 # sphinx54 # tox55 pallets-sphinx-themes==2.0.156 # via -r requirements/docs.in57-pep517==0.10.057+pep517==0.11.058 # via pip-tools59-pip-tools==6.2.059+pip-tools==6.3.060 # via -r requirements/dev.in61-pluggy==0.13.161+platformdirs==2.4.062+ # via virtualenv63+pluggy==1.0.064 # via65 # pytest66 # tox65-pre-commit==2.14.167+pre-commit==2.15.068 # via -r requirements/dev.in69 py==1.10.070 # via71 # pytest72 # tox71-pygments==2.9.073+pygments==2.10.074 # via sphinx75 pyparsing==2.4.776 # via packaging77 pytest==6.2.578 # via -r requirements/tests.in77-pytz==2021.179+pytz==2021.380 # via babel81 pyyaml==5.4.182 # via pre-commit81-requests==2.25.183+requests==2.26.084 # via sphinx85 six==1.16.086 # via87 # tox88 # virtualenv89 snowballstemmer==2.1.090 # via sphinx89-sphinx==4.0.291+sphinx-issues==1.2.092+ # via -r requirements/docs.in93+sphinx==4.2.094 # via95 # -r requirements/docs.in96 # pallets-sphinx-themes97 # sphinx-issues98 # sphinxcontrib-log-cabinet95-sphinx-issues==1.2.096- # via -r requirements/docs.in99 sphinxcontrib-applehelp==1.0.2100 # via sphinx101 sphinxcontrib-devhelp==1.0.2102 # via sphinx101-sphinxcontrib-htmlhelp==1.0.3103+sphinxcontrib-htmlhelp==2.0.0104 # via sphinx105 sphinxcontrib-jsmath==1.0.1106 # via sphinx107 sphinxcontrib-log-cabinet==1.0.1108 # via -r requirements/docs.in109 sphinxcontrib-qthelp==1.0.3110 # via sphinx109-sphinxcontrib-serializinghtml==1.1.4111+sphinxcontrib-serializinghtml==1.1.5112 # via sphinx113 toml==0.10.2114 # via115 # mypy114- # pep517116 # pre-commit117 # pytest118 # tox119+tomli==1.2.1120+ # via pep517118-tox==3.24.3121+tox==3.24.4122 # via -r requirements/dev.in120-typing-extensions==3.10.0.0123+typing-extensions==3.10.0.2124 # via mypy122-urllib3==1.26.4125+urllib3==1.26.7126 # via requests124-virtualenv==20.4.6127+virtualenv==20.8.1128 # via129 # pre-commit130 # tox128-wheel==0.36.2131+wheel==0.37.0132 # via pip-tools133 134 # The following packages are considered to be unsafe in a requirements file:135 # pip1 unmodified linemodified:requirements/docs.txt+11 added-11 removed
6 unmodified lines7 alabaster==0.7.128 # via sphinx9 babel==2.9.110 # via sphinx11-certifi==2020.12.511+certifi==2021.5.3012 # via requests13-chardet==4.0.013+charset-normalizer==2.0.614 # via requests15 docutils==0.17.116 # via sphinx17-idna==2.1017+idna==3.218 # via requests19 imagesize==1.2.020 # via sphinx21 jinja2==3.0.122 # via sphinx23 markupsafe==2.0.124 # via jinja225-packaging==20.925+packaging==21.026 # via27 # pallets-sphinx-themes28 # sphinx29 pallets-sphinx-themes==2.0.130 # via -r requirements/docs.in31-pygments==2.9.031+pygments==2.10.032 # via sphinx33 pyparsing==2.4.734 # via packaging35-pytz==2021.135+pytz==2021.336 # via babel37-requests==2.25.137+requests==2.26.038 # via sphinx39 snowballstemmer==2.1.040 # via sphinx41 sphinx-issues==1.2.042 # via -r requirements/docs.in43-sphinx==4.0.243+sphinx==4.2.044 # via45 # -r requirements/docs.in46 # pallets-sphinx-themes47 # sphinx-issues1 unmodified line49 sphinxcontrib-applehelp==1.0.250 # via sphinx51 sphinxcontrib-devhelp==1.0.252 # via sphinx53-sphinxcontrib-htmlhelp==1.0.353+sphinxcontrib-htmlhelp==2.0.054 # via sphinx55 sphinxcontrib-jsmath==1.0.156 # via sphinx57 sphinxcontrib-log-cabinet==1.0.158 # via -r requirements/docs.in59 sphinxcontrib-qthelp==1.0.360 # via sphinx61-sphinxcontrib-serializinghtml==1.1.461+sphinxcontrib-serializinghtml==1.1.562 # via sphinx63-urllib3==1.26.463+urllib3==1.26.764 # via requests65 66 # The following packages are considered to be unsafe in a requirements file:67 # setuptoolsmodified:requirements/tests.txt+2 added-2 removed
6 unmodified lines7 attrs==21.2.08 # via pytest9 iniconfig==1.1.110 # via pytest11-packaging==20.911+packaging==21.012 # via pytest13-pluggy==0.13.113+pluggy==1.0.014 # via pytest15 py==1.10.016 # via pytest17 pyparsing==2.4.75 unmodified linesmodified:requirements/typing.txt+3 added-3 removed
2 unmodified lines3 # To update, run:4 #5 # pip-compile requirements/typing.in6 #7-mypy==0.9108- # via -r requirements/typing.in7 mypy-extensions==0.4.38 # via mypy9+mypy==0.91010+ # via -r requirements/typing.in11 toml==0.10.212 # via mypy13-typing-extensions==3.10.0.013+typing-extensions==3.10.0.214 # via mypymodified:src/jinja2/filters.py+4 added-4 removed
1348 unmodified lines1349 try:1350 rv = list(value)1351 rv.reverse()1352 return rv1353- except TypeError:1354- raise FilterArgumentError("argument must be iterable")1353+ except TypeError as e:1354+ raise FilterArgumentError("argument must be iterable") from e1355 1356 1357 @pass_environment1358 def do_attr(331 unmodified lines1690 try:1691 name = args[0]1692 args = args[1:]1693 except LookupError:1694- raise FilterArgumentError("map requires a filter argument")1694+ raise FilterArgumentError("map requires a filter argument") from None1695 1696 def func(item: t.Any) -> t.Any:1697 return context.environment.call_filter(1698 name, item, args, kwargs, context=context12 unmodified lines1711 if lookup_attr:1712 try:1713 attr = args[0]1714 except LookupError:1715- raise FilterArgumentError("Missing parameter for attribute name")1715+ raise FilterArgumentError("Missing parameter for attribute name") from None1716 1717 transfunc = make_attrgetter(context.environment, attr)1718 off = 11719 else:105 unmodified linesmodified:src/jinja2/lexer.py+1 added-1 removed
653 unmodified lines654 .decode("unicode-escape")655 )656 except Exception as e:657 msg = str(e).split(":")[-1].strip()658- raise TemplateSyntaxError(msg, lineno, name, filename)658+ raise TemplateSyntaxError(msg, lineno, name, filename) from e659 elif token == TOKEN_INTEGER:660 value = int(value_str.replace("_", ""), 0)661 elif token == TOKEN_FLOAT:662 # remove all "_" first to support more Python versions207 unmodified linesmodified:src/jinja2/loaders.py+10 added-10 removed
334 unmodified lines335 else:336 # Package is a zip file.337 try:338 source = self._loader.get_data(p) # type: ignore339- except OSError:340- raise TemplateNotFound(template)339+ except OSError as e:340+ raise TemplateNotFound(template) from e341 342 # Could use the zip's mtime for all template mtimes, but343 # would need to safely reload the module if it's out of344 # date, so just report it as always current.130 unmodified lines475 def get_loader(self, template: str) -> t.Tuple[BaseLoader, str]:476 try:477 prefix, name = template.split(self.delimiter, 1)478 loader = self.mapping[prefix]479- except (ValueError, KeyError):480- raise TemplateNotFound(template)479+ except (ValueError, KeyError) as e:480+ raise TemplateNotFound(template) from e481 return loader, name482 483 def get_source(484 self, environment: "Environment", template: str485 ) -> t.Tuple[str, t.Optional[str], t.Optional[t.Callable[[], bool]]]:486 loader, name = self.get_loader(template)487 try:488 return loader.get_source(environment, name)489- except TemplateNotFound:489+ except TemplateNotFound as e:490 # re-raise the exception with the correct filename here.491 # (the one that includes the prefix)492- raise TemplateNotFound(template)492+ raise TemplateNotFound(template) from e493 494 @internalcode495 def load(496 self,3 unmodified lines500 ) -> "Template":501 loader, local_name = self.get_loader(name)502 try:503 return loader.load(environment, local_name, globals)504- except TemplateNotFound:504+ except TemplateNotFound as e:505 # re-raise the exception with the correct filename here.506 # (the one that includes the prefix)507- raise TemplateNotFound(name)507+ raise TemplateNotFound(name) from e508 509 def list_templates(self) -> t.List[str]:510 result = []511 for prefix, loader in self.mapping.items():114 unmodified lines626 627 if mod is None:628 try:629 mod = __import__(module, None, None, ["root"])630- except ImportError:631- raise TemplateNotFound(name)630+ except ImportError as e:631+ raise TemplateNotFound(name) from e632 633 # remove the entry from sys.modules, we only want the attribute634 # on the module object we have stored on the loader.635 sys.modules.pop(module, None)7 unmodified linesmodified:src/jinja2/nodes.py+16 added-16 removed
505 unmodified lines506 raise Impossible()507 f = _binop_to_func[self.operator]508 try:509 return f(self.left.as_const(eval_ctx), self.right.as_const(eval_ctx))510- except Exception:511- raise Impossible()510+ except Exception as e:511+ raise Impossible() from e512 513 514 class UnaryExpr(Expr):515 """Baseclass for all unary expressions."""14 unmodified lines530 raise Impossible()531 f = _uaop_to_func[self.operator]532 try:533 return f(self.node.as_const(eval_ctx))534- except Exception:535- raise Impossible()534+ except Exception as e:535+ raise Impossible() from e536 537 538 class Name(Expr):539 """Looks up a name or stores a value in a name.182 unmodified lines722 723 if node.dyn_args is not None:724 try:725 args.extend(node.dyn_args.as_const(eval_ctx))726- except Exception:727- raise Impossible()726+ except Exception as e:727+ raise Impossible() from e728 729 if node.dyn_kwargs is not None:730 try:731 kwargs.update(node.dyn_kwargs.as_const(eval_ctx))732- except Exception:733- raise Impossible()732+ except Exception as e:733+ raise Impossible() from e734 735 return args, kwargs736 737 40 unmodified lines778 args.insert(0, eval_ctx.environment)779 780 try:781 return func(*args, **kwargs)782- except Exception:783- raise Impossible()782+ except Exception as e:783+ raise Impossible() from e784 785 786 class Filter(_FilterTestCommon):787 """Apply a filter to an expression. ``name`` is the name of the58 unmodified lines846 try:847 return eval_ctx.environment.getitem(848 self.node.as_const(eval_ctx), self.arg.as_const(eval_ctx)849 )850- except Exception:851- raise Impossible()850+ except Exception as e:851+ raise Impossible() from e852 853 854 class Getattr(Expr):855 """Get an attribute or item from an expression that is a ascii-only12 unmodified lines868 eval_ctx = get_eval_context(self, eval_ctx)869 870 try:871 return eval_ctx.environment.getattr(self.node.as_const(eval_ctx), self.attr)872- except Exception:873- raise Impossible()872+ except Exception as e:873+ raise Impossible() from e874 875 876 class Slice(Expr):877 """Represents a slice object. This must only be used as argument for50 unmodified lines928 if not result:929 return False930 931 value = new_value932- except Exception:933- raise Impossible()932+ except Exception as e:933+ raise Impossible() from e934 935 return result936 937 268 unmodified linesmodified:src/jinja2/utils.py+1 added-1 removed
822 unmodified lines823 return object.__getattribute__(self, name)824 try:825 return self.__attrs[name]826 except KeyError:827- raise AttributeError(name)827+ raise AttributeError(name) from None828 829 def __setitem__(self, name: str, value: t.Any) -> None:830 self.__attrs[name] = value831 23 unmodified linesmodified:.pre-commit-config.yaml+2 added-2 removed
1 ci:2 autoupdate_schedule: monthly3 repos:4 - repo: https://github.com/asottile/pyupgrade5- rev: v2.25.05+ rev: v2.29.06 hooks:7 - id: pyupgrade8 args: ["--py36-plus"]9 - repo: https://github.com/asottile/reorder_python_imports1 unmodified line11 hooks:12 - id: reorder-python-imports13 args: ["--application-directories", "src"]14 - repo: https://github.com/psf/black15- rev: 21.8b015+ rev: 21.9b016 hooks:17 - id: black18 - repo: https://github.com/PyCQA/flake819 rev: 3.9.29 unmodified linesmodified:setup.cfg+2 added
45 unmodified lines46 [tool:pytest]47 testpaths = tests48 filterwarnings =49 error50+ # Python 3.9 raises a deprecation from internal asyncio code.51+ ignore:The loop argument:DeprecationWarning:asyncio[.]base_events:54252 53 [coverage:run]54 branch = True55 source =53 unmodified lines