[rejected AI] Ignore the codec warning for unknown string escapes - #2267
Closed
mmdverse wants to merge 1 commit into
Closed
[rejected AI] Ignore the codec warning for unknown string escapes#2267mmdverse wants to merge 1 commit into
mmdverse wants to merge 1 commit into
Conversation
The unicode-escape decode in the lexer emits an internal
DeprecationWarning for escape sequences it does not know (e.g.
"\d" in a regex fragment). The warning points at jinja internals
and, under -W error, breaks template compilation with a misleading
TemplateSyntaxError, even though the value is rendered as-is.
Scope a warnings.catch_warnings() around the decode so the warning
is ignored. Output is unchanged and malformed sequences (e.g.
"\xZZ", "\N{unknown name}") still raise TemplateSyntaxError.
Adds a regression test (fails without the fix, passes with it).
Fixes #1156
Member
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1156.
String literals containing an escape sequence that Python does not know
(e.g.
"\d"in a regex fragment) are rendered as-is, but theunicode-escapedecode in the lexer emits an internalDeprecationWarningfor them. The warning points at jinja internalsinstead of the user's template, and under strict warning setups
(
-W error) it becomes aTemplateSyntaxErrorthat stops the templatefrom compiling.
This scopes a
warnings.catch_warnings()around the decode so thecodec's warning is ignored. Notes:
(valid escapes, unknown escapes, non-ASCII input, concatenated
literals, async and sandboxed environments). Changing what an unknown
escape renders to would be a behaviour break, so this only removes
the spurious warning;
\xZZ,\u12,\N{unknown name}) still raiseTemplateSyntaxErrorexactly as before;DeprecationWarningon all of them (verified against CPython 3.14source as well).
Adds a regression test that promotes
DeprecationWarningto an error:it fails without the fix and passes with it.