Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for namespaces in tuple parsing #1664

Merged
merged 2 commits into from
Dec 20, 2024

Conversation

kevin-brown
Copy link
Member

@kevin-brown kevin-brown commented May 2, 2022

This fixes a bug that existed because namespaces within {% set %} were treated as a special case. This special case had the side-effect of bypassing the code which allows for tuples to be assigned to.

The solution was to make tuple handling (and by extension, primary token handling) aware of namespaces so that namespace tokens can be handled appropriately. This is handled in a backwards-compatible way which ensures that we do not try to parse namespace tokens when we otherwise would be expecting to parse out name tokens with attributes.

Fixes #1413

Checklist:

  • Add tests that demonstrate the correct behavior of the change. Tests should fail without the change.
  • Add or update relevant docs, in the docs folder and in code.
  • Add an entry in CHANGES.rst summarizing the change and linking to the issue.
  • Add .. versionchanged:: entries in any relevant code docs.
  • Run pre-commit hooks and fix any issues.
  • Run pytest and tox, no tests failed.

@kevin-brown kevin-brown marked this pull request as ready for review May 2, 2022 20:03
@kevin-brown kevin-brown requested a review from davidism May 2, 2022 20:03
@davidism davidism added this to the 3.1.5 milestone Dec 20, 2024
src/jinja2/compiler.py Outdated Show resolved Hide resolved
@davidism
Copy link
Member

davidism commented Dec 20, 2024

Targeting this for the 3.1.5 release. Needs to be rebased onto latest stable branch (git rebase --onto origin/stable origin/main). I'll step through it in more detail tomorrow, but the only things that jumped out at me were some minor questions.

This fixes a bug that existed because namespaces within `{% set %}`
were treated as a special case. This special case had the side-effect
of bypassing the code which allows for tuples to be assigned to.

The solution was to make tuple handling (and by extension, primary token
handling) aware of namespaces so that namespace tokens can be handled
appropriately. This is handled in a backwards-compatible way which
ensures that we do not try to parse namespace tokens when we otherwise
would be expecting to parse out name tokens with attributes.

Namespace instance checks are moved earlier, and deduplicated, so that
all checks are done before the assignment. Otherwise, the check could be
emitted in the middle of the tuple.
@davidism davidism changed the base branch from main to stable December 20, 2024 22:09
@davidism davidism force-pushed the GH-1413-set-namespace-tuple branch from 48dc4fd to 2c971d7 Compare December 20, 2024 22:10
only emit nsref instance check once per ref name
refactor primary name parsing a bit
@davidism davidism force-pushed the GH-1413-set-namespace-tuple branch from 2c971d7 to b8f4831 Compare December 20, 2024 22:51
@davidism davidism merged commit fbc3a69 into stable Dec 20, 2024
12 checks passed
@davidism davidism deleted the GH-1413-set-namespace-tuple branch December 20, 2024 22:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Namespaces do not allow multi-variable assignments
2 participants