diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 26ac812d3..e5919a664 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,7 +2,7 @@ ci: autoupdate_schedule: monthly repos: - repo: https://github.com/asottile/pyupgrade - rev: v2.25.0 + rev: v2.29.0 hooks: - id: pyupgrade args: ["--py36-plus"] @@ -12,7 +12,7 @@ repos: - id: reorder-python-imports args: ["--application-directories", "src"] - repo: https://github.com/psf/black - rev: 21.8b0 + rev: 21.9b0 hooks: - id: black - repo: https://github.com/PyCQA/flake8 diff --git a/docs/extensions.rst b/docs/extensions.rst index f1033656b..45ead3b71 100644 --- a/docs/extensions.rst +++ b/docs/extensions.rst @@ -123,7 +123,7 @@ The usage of the ``i18n`` extension for template designers is covered in :ref:`the template documentation `. .. _gettext: https://docs.python.org/3/library/gettext.html -.. _Babel: http://babel.pocoo.org/ +.. _Babel: https://babel.pocoo.org/ Whitespace Trimming diff --git a/docs/intro.rst b/docs/intro.rst index 56446a202..9eeaa0540 100644 --- a/docs/intro.rst +++ b/docs/intro.rst @@ -60,4 +60,4 @@ These distributions will not be installed automatically. - `Babel`_ provides translation support in templates. -.. _Babel: http://babel.pocoo.org/ +.. _Babel: https://babel.pocoo.org/ diff --git a/docs/make.bat b/docs/make.bat index 7893348a1..b16225546 100644 --- a/docs/make.bat +++ b/docs/make.bat @@ -21,7 +21,7 @@ if errorlevel 9009 ( echo.may add the Sphinx directory to PATH. echo. echo.If you don't have Sphinx installed, grab it from - echo.http://sphinx-doc.org/ + echo.https://www.sphinx-doc.org/ exit /b 1 ) diff --git a/requirements/dev.txt b/requirements/dev.txt index 1c76369c5..b212c8927 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -6,31 +6,31 @@ # alabaster==0.7.12 # via sphinx -appdirs==1.4.4 - # via virtualenv attrs==21.2.0 # via pytest babel==2.9.1 # via sphinx -certifi==2020.12.5 +backports.entry-points-selectable==1.1.0 + # via virtualenv +certifi==2021.5.30 # via requests -cfgv==3.3.0 +cfgv==3.3.1 # via pre-commit -chardet==4.0.0 +charset-normalizer==2.0.6 # via requests click==8.0.1 # via pip-tools -distlib==0.3.1 +distlib==0.3.3 # via virtualenv docutils==0.17.1 # via sphinx -filelock==3.0.12 +filelock==3.3.0 # via # tox # virtualenv -identify==2.2.4 +identify==2.3.0 # via pre-commit -idna==2.10 +idna==3.2 # via requests imagesize==1.2.0 # via sphinx @@ -40,13 +40,13 @@ jinja2==3.0.1 # via sphinx markupsafe==2.0.1 # via jinja2 -mypy==0.910 - # via -r requirements/typing.in mypy-extensions==0.4.3 # via mypy +mypy==0.910 + # via -r requirements/typing.in nodeenv==1.6.0 # via pre-commit -packaging==20.9 +packaging==21.0 # via # pallets-sphinx-themes # pytest @@ -54,31 +54,33 @@ packaging==20.9 # tox pallets-sphinx-themes==2.0.1 # via -r requirements/docs.in -pep517==0.10.0 +pep517==0.11.0 # via pip-tools -pip-tools==6.2.0 +pip-tools==6.3.0 # via -r requirements/dev.in -pluggy==0.13.1 +platformdirs==2.4.0 + # via virtualenv +pluggy==1.0.0 # via # pytest # tox -pre-commit==2.14.1 +pre-commit==2.15.0 # via -r requirements/dev.in py==1.10.0 # via # pytest # tox -pygments==2.9.0 +pygments==2.10.0 # via sphinx pyparsing==2.4.7 # via packaging pytest==6.2.5 # via -r requirements/tests.in -pytz==2021.1 +pytz==2021.3 # via babel pyyaml==5.4.1 # via pre-commit -requests==2.25.1 +requests==2.26.0 # via sphinx six==1.16.0 # via @@ -86,19 +88,19 @@ six==1.16.0 # virtualenv snowballstemmer==2.1.0 # via sphinx -sphinx==4.0.2 +sphinx-issues==1.2.0 + # via -r requirements/docs.in +sphinx==4.2.0 # via # -r requirements/docs.in # pallets-sphinx-themes # sphinx-issues # sphinxcontrib-log-cabinet -sphinx-issues==1.2.0 - # via -r requirements/docs.in sphinxcontrib-applehelp==1.0.2 # via sphinx sphinxcontrib-devhelp==1.0.2 # via sphinx -sphinxcontrib-htmlhelp==1.0.3 +sphinxcontrib-htmlhelp==2.0.0 # via sphinx sphinxcontrib-jsmath==1.0.1 # via sphinx @@ -106,26 +108,27 @@ sphinxcontrib-log-cabinet==1.0.1 # via -r requirements/docs.in sphinxcontrib-qthelp==1.0.3 # via sphinx -sphinxcontrib-serializinghtml==1.1.4 +sphinxcontrib-serializinghtml==1.1.5 # via sphinx toml==0.10.2 # via # mypy - # pep517 # pre-commit # pytest # tox -tox==3.24.3 +tomli==1.2.1 + # via pep517 +tox==3.24.4 # via -r requirements/dev.in -typing-extensions==3.10.0.0 +typing-extensions==3.10.0.2 # via mypy -urllib3==1.26.4 +urllib3==1.26.7 # via requests -virtualenv==20.4.6 +virtualenv==20.8.1 # via # pre-commit # tox -wheel==0.36.2 +wheel==0.37.0 # via pip-tools # The following packages are considered to be unsafe in a requirements file: diff --git a/requirements/docs.txt b/requirements/docs.txt index 93878a7e1..a35d34007 100644 --- a/requirements/docs.txt +++ b/requirements/docs.txt @@ -8,13 +8,13 @@ alabaster==0.7.12 # via sphinx babel==2.9.1 # via sphinx -certifi==2020.12.5 +certifi==2021.5.30 # via requests -chardet==4.0.0 +charset-normalizer==2.0.6 # via requests docutils==0.17.1 # via sphinx -idna==2.10 +idna==3.2 # via requests imagesize==1.2.0 # via sphinx @@ -22,25 +22,25 @@ jinja2==3.0.1 # via sphinx markupsafe==2.0.1 # via jinja2 -packaging==20.9 +packaging==21.0 # via # pallets-sphinx-themes # sphinx pallets-sphinx-themes==2.0.1 # via -r requirements/docs.in -pygments==2.9.0 +pygments==2.10.0 # via sphinx pyparsing==2.4.7 # via packaging -pytz==2021.1 +pytz==2021.3 # via babel -requests==2.25.1 +requests==2.26.0 # via sphinx snowballstemmer==2.1.0 # via sphinx sphinx-issues==1.2.0 # via -r requirements/docs.in -sphinx==4.0.2 +sphinx==4.2.0 # via # -r requirements/docs.in # pallets-sphinx-themes @@ -50,7 +50,7 @@ sphinxcontrib-applehelp==1.0.2 # via sphinx sphinxcontrib-devhelp==1.0.2 # via sphinx -sphinxcontrib-htmlhelp==1.0.3 +sphinxcontrib-htmlhelp==2.0.0 # via sphinx sphinxcontrib-jsmath==1.0.1 # via sphinx @@ -58,9 +58,9 @@ sphinxcontrib-log-cabinet==1.0.1 # via -r requirements/docs.in sphinxcontrib-qthelp==1.0.3 # via sphinx -sphinxcontrib-serializinghtml==1.1.4 +sphinxcontrib-serializinghtml==1.1.5 # via sphinx -urllib3==1.26.4 +urllib3==1.26.7 # via requests # The following packages are considered to be unsafe in a requirements file: diff --git a/requirements/tests.txt b/requirements/tests.txt index 89031f877..b89972937 100644 --- a/requirements/tests.txt +++ b/requirements/tests.txt @@ -8,9 +8,9 @@ attrs==21.2.0 # via pytest iniconfig==1.1.1 # via pytest -packaging==20.9 +packaging==21.0 # via pytest -pluggy==0.13.1 +pluggy==1.0.0 # via pytest py==1.10.0 # via pytest diff --git a/requirements/typing.txt b/requirements/typing.txt index fa04c8ad5..f5af819ed 100644 --- a/requirements/typing.txt +++ b/requirements/typing.txt @@ -4,11 +4,11 @@ # # pip-compile requirements/typing.in # -mypy==0.910 - # via -r requirements/typing.in mypy-extensions==0.4.3 # via mypy +mypy==0.910 + # via -r requirements/typing.in toml==0.10.2 # via mypy -typing-extensions==3.10.0.0 +typing-extensions==3.10.0.2 # via mypy diff --git a/setup.cfg b/setup.cfg index a56d5535e..f952317e1 100644 --- a/setup.cfg +++ b/setup.cfg @@ -47,6 +47,8 @@ babel.extractors = testpaths = tests filterwarnings = error + # Python 3.9 raises a deprecation from internal asyncio code. + ignore:The loop argument:DeprecationWarning:asyncio[.]base_events:542 [coverage:run] branch = True diff --git a/src/jinja2/filters.py b/src/jinja2/filters.py index c8d41dab4..ffb98bf4e 100644 --- a/src/jinja2/filters.py +++ b/src/jinja2/filters.py @@ -1350,8 +1350,8 @@ def do_reverse(value: t.Union[str, t.Iterable[V]]) -> t.Union[str, t.Iterable[V] rv = list(value) rv.reverse() return rv - except TypeError: - raise FilterArgumentError("argument must be iterable") + except TypeError as e: + raise FilterArgumentError("argument must be iterable") from e @pass_environment @@ -1691,7 +1691,7 @@ def prepare_map( name = args[0] args = args[1:] except LookupError: - raise FilterArgumentError("map requires a filter argument") + raise FilterArgumentError("map requires a filter argument") from None def func(item: t.Any) -> t.Any: return context.environment.call_filter( @@ -1712,7 +1712,7 @@ def prepare_select_or_reject( try: attr = args[0] except LookupError: - raise FilterArgumentError("Missing parameter for attribute name") + raise FilterArgumentError("Missing parameter for attribute name") from None transfunc = make_attrgetter(context.environment, attr) off = 1 diff --git a/src/jinja2/lexer.py b/src/jinja2/lexer.py index 972601267..c25ab0f69 100644 --- a/src/jinja2/lexer.py +++ b/src/jinja2/lexer.py @@ -655,7 +655,7 @@ def wrap( ) except Exception as e: msg = str(e).split(":")[-1].strip() - raise TemplateSyntaxError(msg, lineno, name, filename) + raise TemplateSyntaxError(msg, lineno, name, filename) from e elif token == TOKEN_INTEGER: value = int(value_str.replace("_", ""), 0) elif token == TOKEN_FLOAT: diff --git a/src/jinja2/loaders.py b/src/jinja2/loaders.py index bde6a1ca4..db04f0f68 100644 --- a/src/jinja2/loaders.py +++ b/src/jinja2/loaders.py @@ -336,8 +336,8 @@ def up_to_date() -> bool: # Package is a zip file. try: source = self._loader.get_data(p) # type: ignore - except OSError: - raise TemplateNotFound(template) + except OSError as e: + raise TemplateNotFound(template) from e # Could use the zip's mtime for all template mtimes, but # would need to safely reload the module if it's out of @@ -476,8 +476,8 @@ def get_loader(self, template: str) -> t.Tuple[BaseLoader, str]: try: prefix, name = template.split(self.delimiter, 1) loader = self.mapping[prefix] - except (ValueError, KeyError): - raise TemplateNotFound(template) + except (ValueError, KeyError) as e: + raise TemplateNotFound(template) from e return loader, name def get_source( @@ -486,10 +486,10 @@ def get_source( loader, name = self.get_loader(template) try: return loader.get_source(environment, name) - except TemplateNotFound: + except TemplateNotFound as e: # re-raise the exception with the correct filename here. # (the one that includes the prefix) - raise TemplateNotFound(template) + raise TemplateNotFound(template) from e @internalcode def load( @@ -501,10 +501,10 @@ def load( loader, local_name = self.get_loader(name) try: return loader.load(environment, local_name, globals) - except TemplateNotFound: + except TemplateNotFound as e: # re-raise the exception with the correct filename here. # (the one that includes the prefix) - raise TemplateNotFound(name) + raise TemplateNotFound(name) from e def list_templates(self) -> t.List[str]: result = [] @@ -627,8 +627,8 @@ def load( if mod is None: try: mod = __import__(module, None, None, ["root"]) - except ImportError: - raise TemplateNotFound(name) + except ImportError as e: + raise TemplateNotFound(name) from e # remove the entry from sys.modules, we only want the attribute # on the module object we have stored on the loader. diff --git a/src/jinja2/nodes.py b/src/jinja2/nodes.py index 1feb543e9..226e729c0 100644 --- a/src/jinja2/nodes.py +++ b/src/jinja2/nodes.py @@ -507,8 +507,8 @@ def as_const(self, eval_ctx: t.Optional[EvalContext] = None) -> t.Any: f = _binop_to_func[self.operator] try: return f(self.left.as_const(eval_ctx), self.right.as_const(eval_ctx)) - except Exception: - raise Impossible() + except Exception as e: + raise Impossible() from e class UnaryExpr(Expr): @@ -531,8 +531,8 @@ def as_const(self, eval_ctx: t.Optional[EvalContext] = None) -> t.Any: f = _uaop_to_func[self.operator] try: return f(self.node.as_const(eval_ctx)) - except Exception: - raise Impossible() + except Exception as e: + raise Impossible() from e class Name(Expr): @@ -723,14 +723,14 @@ def args_as_const( if node.dyn_args is not None: try: args.extend(node.dyn_args.as_const(eval_ctx)) - except Exception: - raise Impossible() + except Exception as e: + raise Impossible() from e if node.dyn_kwargs is not None: try: kwargs.update(node.dyn_kwargs.as_const(eval_ctx)) - except Exception: - raise Impossible() + except Exception as e: + raise Impossible() from e return args, kwargs @@ -779,8 +779,8 @@ def as_const(self, eval_ctx: t.Optional[EvalContext] = None) -> t.Any: try: return func(*args, **kwargs) - except Exception: - raise Impossible() + except Exception as e: + raise Impossible() from e class Filter(_FilterTestCommon): @@ -847,8 +847,8 @@ def as_const(self, eval_ctx: t.Optional[EvalContext] = None) -> t.Any: return eval_ctx.environment.getitem( self.node.as_const(eval_ctx), self.arg.as_const(eval_ctx) ) - except Exception: - raise Impossible() + except Exception as e: + raise Impossible() from e class Getattr(Expr): @@ -869,8 +869,8 @@ def as_const(self, eval_ctx: t.Optional[EvalContext] = None) -> t.Any: try: return eval_ctx.environment.getattr(self.node.as_const(eval_ctx), self.attr) - except Exception: - raise Impossible() + except Exception as e: + raise Impossible() from e class Slice(Expr): @@ -929,8 +929,8 @@ def as_const(self, eval_ctx: t.Optional[EvalContext] = None) -> t.Any: return False value = new_value - except Exception: - raise Impossible() + except Exception as e: + raise Impossible() from e return result diff --git a/src/jinja2/utils.py b/src/jinja2/utils.py index 2a2641c0c..567185f41 100644 --- a/src/jinja2/utils.py +++ b/src/jinja2/utils.py @@ -824,7 +824,7 @@ def __getattribute__(self, name: str) -> t.Any: try: return self.__attrs[name] except KeyError: - raise AttributeError(name) + raise AttributeError(name) from None def __setitem__(self, name: str, value: t.Any) -> None: self.__attrs[name] = value