Repository navigation
Use raw strings for regular expressions in asvs.py - #3450
Merged
Merged
Conversation
Python 3.12+ emits a SyntaxWarning for invalid escape sequences such as '\d', '\s' and '\*' in regular string literals, and this is planned to become a SyntaxError in a future Python version. Switch the affected regex literals to raw strings. The compiled patterns are unchanged.
tghosth
approved these changes
Nov 27, 2026
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.
This Pull Request relates to issue #... (none yet; this is a small bug fix in the export tooling, see CONTRIBUTING "Typos and bug fixes may be exceptions". Happy to open an issue first if preferred.)
What
5.0/tools/asvs.pybuilds several regular expressions from normal (non-raw) string literals that contain\d,\s,\w,\*and\|. Since Python 3.12 every run of the export tool prints aSyntaxWarning: invalid escape sequencefor each of them (8 warnings), and Python has announced that these will eventually become aSyntaxError. The Docker image builds onalpine:3, which ships Python 3.12+, so the warnings show up in document builds today.This PR adds the
rprefix to the affected literals (version, filename, chapter heading, section heading and requirement regexes). No pattern changes meaning; the existing[^\n]in two of them is equivalent in raw and non-raw form.4.0/tools/asvs.pyhas the same 8 warnings. I left it unchanged because CONTRIBUTING says the 4.0 folder is frozen at 4.0.3.How I tested
python3 -W errorcompile ofasvs.py: fails before (SyntaxError: invalid escape sequence '\d'), passes after.python tools/export.py --language enfor every working--format(json, json_flat, xml, csv, cdx_json, raw, json_xl, json_legacy, json_flat_legacy, csv_legacy, xml_legacy): output byte-identical before and after (cdx_json compared without its randomserialNumber/timestamp).--verify-onlystill reports 345 requirements for en.v5.0.0branch (en, pt, fa, zh-cn, ko, tr, ru, fr, id, pl) for json/csv/xml/json_flat_legacy: identical output.