From f39ffa0d8af19f464e99402ca3681515e371b737 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 7 Mar 2023 03:52:21 +0000 Subject: [PATCH 1/9] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/peterdemin/pip-compile-multi: v2.6.1 → v2.6.2](https://github.com/peterdemin/pip-compile-multi/compare/v2.6.1...v2.6.2) --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e734c0aa3..a6188279a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -23,7 +23,7 @@ repos: - id: flake8 additional_dependencies: [flake8-bugbear] - repo: https://github.com/peterdemin/pip-compile-multi - rev: v2.6.1 + rev: v2.6.2 hooks: - id: pip-compile-multi-verify - repo: https://github.com/pre-commit/pre-commit-hooks From 832bdaadfce39239824a984970fb4f21d9f513e1 Mon Sep 17 00:00:00 2001 From: David Lord Date: Tue, 7 Mar 2023 06:55:44 -0800 Subject: [PATCH 2/9] address flake8 findings --- scripts/generate_identifier_pattern.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/generate_identifier_pattern.py b/scripts/generate_identifier_pattern.py index 6b4795357..baf035eae 100755 --- a/scripts/generate_identifier_pattern.py +++ b/scripts/generate_identifier_pattern.py @@ -29,8 +29,8 @@ def collapse_ranges(data): Source: https://stackoverflow.com/a/4629241/400617 """ - for _, b in itertools.groupby(enumerate(data), lambda x: ord(x[1]) - x[0]): - b = list(b) + for _, g in itertools.groupby(enumerate(data), lambda x: ord(x[1]) - x[0]): + b = list(g) yield b[0][1], b[-1][1] From c8c3c846d5db9bee16350c9d5eb479924a37bafa Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 4 Apr 2023 06:32:14 +0000 Subject: [PATCH 3/9] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/psf/black: 23.1.0 → 23.3.0](https://github.com/psf/black/compare/23.1.0...23.3.0) --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a6188279a..6834a669e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -14,7 +14,7 @@ repos: args: ["--application-directories", "src"] additional_dependencies: ["setuptools>60.9"] - repo: https://github.com/psf/black - rev: 23.1.0 + rev: 23.3.0 hooks: - id: black - repo: https://github.com/PyCQA/flake8 From a24a4b15747a869ec4b0f49f1e9d93ab6851f699 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 2 May 2023 04:33:39 +0000 Subject: [PATCH 4/9] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/asottile/pyupgrade: v3.3.1 → v3.3.2](https://github.com/asottile/pyupgrade/compare/v3.3.1...v3.3.2) --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6834a669e..9c2bc0b9f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,7 +3,7 @@ ci: autoupdate_schedule: monthly repos: - repo: https://github.com/asottile/pyupgrade - rev: v3.3.1 + rev: v3.3.2 hooks: - id: pyupgrade args: ["--py37-plus"] From 7e691a08628b7221d2ed188fd43fcc21e830c1ed Mon Sep 17 00:00:00 2001 From: David Lord Date: Thu, 1 Jun 2023 08:06:33 -0700 Subject: [PATCH 5/9] update metadata --- setup.cfg | 2 -- 1 file changed, 2 deletions(-) diff --git a/setup.cfg b/setup.cfg index 96ce202ef..99fec8081 100644 --- a/setup.cfg +++ b/setup.cfg @@ -12,8 +12,6 @@ project_urls = Chat = https://discord.gg/pallets license = BSD-3-Clause license_files = LICENSE.rst -author = Armin Ronacher -author_email = armin.ronacher@active-4.com maintainer = Pallets maintainer_email = contact@palletsprojects.com description = A very fast and expressive template engine. From bfceede8adca0371dc957d05dcdf4c0e2f1e8d3d Mon Sep 17 00:00:00 2001 From: David Lord Date: Thu, 1 Jun 2023 08:08:24 -0700 Subject: [PATCH 6/9] remove unused links --- README.rst | 2 -- docs/conf.py | 2 -- setup.cfg | 1 - 3 files changed, 5 deletions(-) diff --git a/README.rst b/README.rst index a197aea64..94b22ecab 100644 --- a/README.rst +++ b/README.rst @@ -73,6 +73,4 @@ Links - PyPI Releases: https://pypi.org/project/Jinja2/ - Source Code: https://github.com/pallets/jinja/ - Issue Tracker: https://github.com/pallets/jinja/issues/ -- Website: https://palletsprojects.com/p/jinja/ -- Twitter: https://twitter.com/PalletsTeam - Chat: https://discord.gg/pallets diff --git a/docs/conf.py b/docs/conf.py index f65d462b3..1483ce6e8 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -32,8 +32,6 @@ ProjectLink("PyPI Releases", "https://pypi.org/project/Jinja2/"), ProjectLink("Source Code", "https://github.com/pallets/jinja/"), ProjectLink("Issue Tracker", "https://github.com/pallets/jinja/issues/"), - ProjectLink("Website", "https://palletsprojects.com/p/jinja/"), - ProjectLink("Twitter", "https://twitter.com/PalletsTeam"), ProjectLink("Chat", "https://discord.gg/pallets"), ] } diff --git a/setup.cfg b/setup.cfg index 99fec8081..ec8a77571 100644 --- a/setup.cfg +++ b/setup.cfg @@ -8,7 +8,6 @@ project_urls = Changes = https://jinja.palletsprojects.com/changes/ Source Code = https://github.com/pallets/jinja/ Issue Tracker = https://github.com/pallets/jinja/issues/ - Twitter = https://twitter.com/PalletsTeam Chat = https://discord.gg/pallets license = BSD-3-Clause license_files = LICENSE.rst From 37f5b058ee4aaa01994ae4d378fc015bde484933 Mon Sep 17 00:00:00 2001 From: David Lord Date: Thu, 1 Jun 2023 10:31:10 -0700 Subject: [PATCH 7/9] start version 3.1.3 --- CHANGES.rst | 6 ++++++ src/jinja2/__init__.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index fede06ed3..f609ab34a 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,5 +1,11 @@ .. currentmodule:: jinja2 +Version 3.1.3 +------------- + +Unreleased + + Version 3.1.2 ------------- diff --git a/src/jinja2/__init__.py b/src/jinja2/__init__.py index e32392679..f2415bb65 100644 --- a/src/jinja2/__init__.py +++ b/src/jinja2/__init__.py @@ -34,4 +34,4 @@ from .utils import pass_eval_context as pass_eval_context from .utils import select_autoescape as select_autoescape -__version__ = "3.1.2" +__version__ = "3.1.3.dev" From 051df10c7b95b735ee53eeb1e9c8de1eb48ead14 Mon Sep 17 00:00:00 2001 From: David Lord Date: Thu, 1 Jun 2023 10:42:27 -0700 Subject: [PATCH 8/9] fix check for empty required block (#1858) --- CHANGES.rst | 3 +++ src/jinja2/parser.py | 14 ++++++++------ tests/test_inheritance.py | 36 ++++++++++++++++++++++-------------- 3 files changed, 33 insertions(+), 20 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index f609ab34a..36db0843a 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,6 +5,9 @@ Version 3.1.3 Unreleased +- Fix compiler error when checking if required blocks in parent templates are + empty. :pr:`1858` + Version 3.1.2 ------------- diff --git a/src/jinja2/parser.py b/src/jinja2/parser.py index cefce2dfa..12703a97a 100644 --- a/src/jinja2/parser.py +++ b/src/jinja2/parser.py @@ -311,12 +311,14 @@ def parse_block(self) -> nodes.Block: # enforce that required blocks only contain whitespace or comments # by asserting that the body, if not empty, is just TemplateData nodes # with whitespace data - if node.required and not all( - isinstance(child, nodes.TemplateData) and child.data.isspace() - for body in node.body - for child in body.nodes # type: ignore - ): - self.fail("Required blocks can only contain comments or whitespace") + if node.required: + for body_node in node.body: + if not isinstance(body_node, nodes.Output) or any( + not isinstance(output_node, nodes.TemplateData) + or not output_node.data.isspace() + for output_node in body_node.nodes + ): + self.fail("Required blocks can only contain comments or whitespace") self.stream.skip_if("name:" + node.name) return node diff --git a/tests/test_inheritance.py b/tests/test_inheritance.py index 0c20d4da7..8398f4df5 100644 --- a/tests/test_inheritance.py +++ b/tests/test_inheritance.py @@ -287,26 +287,34 @@ def test_invalid_required(self, env): env = Environment( loader=DictLoader( { - "default": "{% block x required %}data {# #}{% endblock %}", - "default1": "{% block x required %}{% block y %}" - "{% endblock %} {% endblock %}", - "default2": "{% block x required %}{% if true %}" - "{% endif %} {% endblock %}", - "level1": "{% if default %}{% extends default %}" - "{% else %}{% extends 'default' %}{% endif %}" - "{%- block x %}CHILD{% endblock %}", + "empty": "{% block x required %}{% endblock %}", + "blank": "{% block x required %} {# c #}{% endblock %}", + "text": "{% block x required %}data {# c #}{% endblock %}", + "block": "{% block x required %}{% block y %}" + "{% endblock %}{% endblock %}", + "if": "{% block x required %}{% if true %}" + "{% endif %}{% endblock %}", + "top": "{% extends t %}{% block x %}CHILD{% endblock %}", } ) ) - t = env.get_template("level1") + t = env.get_template("top") + assert t.render(t="empty") == "CHILD" + assert t.render(t="blank") == "CHILD" - with pytest.raises( + required_block_check = pytest.raises( TemplateSyntaxError, match="Required blocks can only contain comments or whitespace", - ): - assert t.render(default="default") - assert t.render(default="default2") - assert t.render(default="default3") + ) + + with required_block_check: + t.render(t="text") + + with required_block_check: + t.render(t="block") + + with required_block_check: + t.render(t="if") def test_required_with_scope(self, env): env = Environment( From ae312b3065d83085744cfb3c051f06c90a9b389a Mon Sep 17 00:00:00 2001 From: David Lord Date: Thu, 1 Jun 2023 10:47:07 -0700 Subject: [PATCH 9/9] update dependencies --- .pre-commit-config.yaml | 4 ++-- requirements/build.txt | 10 ++++------ requirements/dev.txt | 32 ++++++++++++++++---------------- requirements/docs.txt | 30 ++++++++++++++---------------- requirements/tests.txt | 10 ++++------ requirements/typing.txt | 6 +++--- setup.cfg | 3 +-- src/jinja2/environment.py | 2 +- src/jinja2/nativetypes.py | 2 +- src/jinja2/utils.py | 2 +- tests/test_filters.py | 2 ++ tests/test_inheritance.py | 3 +++ 12 files changed, 52 insertions(+), 54 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9c2bc0b9f..620bd11f0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,7 +3,7 @@ ci: autoupdate_schedule: monthly repos: - repo: https://github.com/asottile/pyupgrade - rev: v3.3.2 + rev: v3.4.0 hooks: - id: pyupgrade args: ["--py37-plus"] @@ -23,7 +23,7 @@ repos: - id: flake8 additional_dependencies: [flake8-bugbear] - repo: https://github.com/peterdemin/pip-compile-multi - rev: v2.6.2 + rev: v2.6.3 hooks: - id: pip-compile-multi-verify - repo: https://github.com/pre-commit/pre-commit-hooks diff --git a/requirements/build.txt b/requirements/build.txt index a735b3d0d..98175b856 100644 --- a/requirements/build.txt +++ b/requirements/build.txt @@ -5,13 +5,11 @@ # # pip-compile-multi # -build==0.9.0 +build==0.10.0 # via -r requirements/build.in -packaging==23.0 +packaging==23.1 # via build -pep517==0.13.0 +pyproject-hooks==1.0.0 # via build tomli==2.0.1 - # via - # build - # pep517 + # via build diff --git a/requirements/dev.txt b/requirements/dev.txt index bde64ee36..99a6f0346 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -8,9 +8,9 @@ -r docs.txt -r tests.txt -r typing.txt -build==0.9.0 +build==0.10.0 # via pip-tools -cachetools==5.2.0 +cachetools==5.3.1 # via tox cfgv==3.3.1 # via pre-commit @@ -24,39 +24,39 @@ colorama==0.4.6 # via tox distlib==0.3.6 # via virtualenv -filelock==3.9.0 +filelock==3.12.0 # via # tox # virtualenv -identify==2.5.11 +identify==2.5.24 # via pre-commit -nodeenv==1.7.0 +nodeenv==1.8.0 # via pre-commit -pep517==0.13.0 - # via build -pip-compile-multi==2.6.1 +pip-compile-multi==2.6.3 # via -r requirements/dev.in -pip-tools==6.12.1 +pip-tools==6.13.0 # via pip-compile-multi -platformdirs==2.6.2 +platformdirs==3.5.1 # via # tox # virtualenv -pre-commit==2.21.0 +pre-commit==3.3.2 # via -r requirements/dev.in -pyproject-api==1.2.1 +pyproject-api==1.5.1 # via tox +pyproject-hooks==1.0.0 + # via build pyyaml==6.0 # via pre-commit -toposort==1.7 +toposort==1.10 # via pip-compile-multi -tox==4.1.0 +tox==4.5.2 # via -r requirements/dev.in -virtualenv==20.17.1 +virtualenv==20.23.0 # via # pre-commit # tox -wheel==0.38.4 +wheel==0.40.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 618301091..2c36046b0 100644 --- a/requirements/docs.txt +++ b/requirements/docs.txt @@ -5,15 +5,15 @@ # # pip-compile-multi # -alabaster==0.7.12 +alabaster==0.7.13 # via sphinx -babel==2.11.0 +babel==2.12.1 # via sphinx -certifi==2022.12.7 +certifi==2023.5.7 # via requests -charset-normalizer==2.1.1 +charset-normalizer==3.1.0 # via requests -docutils==0.19 +docutils==0.20.1 # via sphinx idna==3.4 # via requests @@ -21,23 +21,21 @@ imagesize==1.4.1 # via sphinx jinja2==3.1.2 # via sphinx -markupsafe==2.1.1 +markupsafe==2.1.2 # via jinja2 -packaging==22.0 +packaging==23.1 # via # pallets-sphinx-themes # sphinx -pallets-sphinx-themes==2.0.3 +pallets-sphinx-themes==2.1.0 # via -r requirements/docs.in -pygments==2.13.0 +pygments==2.15.1 # via sphinx -pytz==2022.7 - # via babel -requests==2.28.1 +requests==2.31.0 # via sphinx snowballstemmer==2.2.0 # via sphinx -sphinx==6.0.0 +sphinx==7.0.1 # via # -r requirements/docs.in # pallets-sphinx-themes @@ -45,11 +43,11 @@ sphinx==6.0.0 # sphinxcontrib-log-cabinet sphinx-issues==3.0.1 # via -r requirements/docs.in -sphinxcontrib-applehelp==1.0.2 +sphinxcontrib-applehelp==1.0.4 # via sphinx sphinxcontrib-devhelp==1.0.2 # via sphinx -sphinxcontrib-htmlhelp==2.0.0 +sphinxcontrib-htmlhelp==2.0.1 # via sphinx sphinxcontrib-jsmath==1.0.1 # via sphinx @@ -59,5 +57,5 @@ sphinxcontrib-qthelp==1.0.3 # via sphinx sphinxcontrib-serializinghtml==1.1.5 # via sphinx -urllib3==1.26.13 +urllib3==2.0.2 # via requests diff --git a/requirements/tests.txt b/requirements/tests.txt index fa8c24a27..70ca162b7 100644 --- a/requirements/tests.txt +++ b/requirements/tests.txt @@ -5,17 +5,15 @@ # # pip-compile-multi # -attrs==22.2.0 +exceptiongroup==1.1.1 # via pytest -exceptiongroup==1.1.0 +iniconfig==2.0.0 # via pytest -iniconfig==1.1.1 - # via pytest -packaging==22.0 +packaging==23.1 # via pytest pluggy==1.0.0 # via pytest -pytest==7.2.0 +pytest==7.3.1 # via -r requirements/tests.in tomli==2.0.1 # via pytest diff --git a/requirements/typing.txt b/requirements/typing.txt index a70f3f5ce..bc63c0f84 100644 --- a/requirements/typing.txt +++ b/requirements/typing.txt @@ -5,11 +5,11 @@ # # pip-compile-multi # -mypy==0.991 +mypy==1.3.0 # via -r requirements/typing.in -mypy-extensions==0.4.3 +mypy-extensions==1.0.0 # via mypy tomli==2.0.1 # via mypy -typing-extensions==4.4.0 +typing-extensions==4.6.2 # via mypy diff --git a/setup.cfg b/setup.cfg index ec8a77571..cc85bd2f2 100644 --- a/setup.cfg +++ b/setup.cfg @@ -44,8 +44,7 @@ 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 + ignore:ast:DeprecationWarning [coverage:run] branch = True diff --git a/src/jinja2/environment.py b/src/jinja2/environment.py index 88b26662f..9ec7fe76f 100644 --- a/src/jinja2/environment.py +++ b/src/jinja2/environment.py @@ -701,7 +701,7 @@ def _compile(self, source: str, filename: str) -> CodeType: .. versionadded:: 2.5 """ - return compile(source, filename, "exec") # type: ignore + return compile(source, filename, "exec") @typing.overload def compile( # type: ignore diff --git a/src/jinja2/nativetypes.py b/src/jinja2/nativetypes.py index ac0861034..71db8cc31 100644 --- a/src/jinja2/nativetypes.py +++ b/src/jinja2/nativetypes.py @@ -106,7 +106,7 @@ def render(self, *args: t.Any, **kwargs: t.Any) -> t.Any: try: return self.environment_class.concat( # type: ignore - self.root_render_func(ctx) # type: ignore + self.root_render_func(ctx) ) except Exception: return self.environment.handle_exception() diff --git a/src/jinja2/utils.py b/src/jinja2/utils.py index 9b5f5a50e..94525a0e6 100644 --- a/src/jinja2/utils.py +++ b/src/jinja2/utils.py @@ -182,7 +182,7 @@ def object_type_repr(obj: t.Any) -> str: def pformat(obj: t.Any) -> str: """Format an object using :func:`pprint.pformat`.""" - from pprint import pformat # type: ignore + from pprint import pformat return pformat(obj) diff --git a/tests/test_filters.py b/tests/test_filters.py index 73f0f0be3..32897c546 100644 --- a/tests/test_filters.py +++ b/tests/test_filters.py @@ -870,4 +870,6 @@ def test_filter_undefined_in_condexpr(self, env): with pytest.raises(TemplateRuntimeError, match="No filter named 'f'"): t1.render(x=42) + + with pytest.raises(TemplateRuntimeError, match="No filter named 'f'"): t2.render(x=42) diff --git a/tests/test_inheritance.py b/tests/test_inheritance.py index 8398f4df5..0a525e7ac 100644 --- a/tests/test_inheritance.py +++ b/tests/test_inheritance.py @@ -355,8 +355,11 @@ def test_duplicate_required_or_scoped(self, env): ) ) tmpl = env.get_template("child") + with pytest.raises(TemplateSyntaxError): tmpl.render(default="default1", seq=list(range(3))) + + with pytest.raises(TemplateSyntaxError): tmpl.render(default="default2", seq=list(range(3)))