Repository navigation
Use raw strings for the remaining regex examples - #492
Open
prawalpokharel wants to merge 2 commits into
Open
prawalpokharel wants to merge 2 commits into
prawalpokharel wants to merge 2 commits into
Conversation
PR csev#447 added the r prefix to the regular expressions in code3/re05.py to re11.py. A few were missed and still print "SyntaxWarning: invalid escape sequence" on Python 3.12 and later: - the money example in book3/11-regex.mkd and its copy in html3/11-regex.php - code3/re14.py - four header patterns in code3/gmane/gmane.py and two in code3/gmane/gmodel.py Only the r prefix is added. Each pattern means the same thing to the re module as before.
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.
PR #447 added the
rprefix to the regular expressions incode3/re05.pytore11.py. A few were missed. They still use plain strings with backslashes, so Python 3.12 and later printSyntaxWarning: invalid escape sequencefor them:book3/11-regex.mkd, with its copies inhtml3/11-regex.phpandbook3/translation/book-tl/11-regex.mkdcode3/re14.pycode3/gmane/gmane.pyand two incode3/gmane/gmodel.pyThe only change is the added
r. Each pattern parses to the same regex as before (checked on Python 3.9 to 3.15), andre14.pyprints the same output.This fails before the change and passes after it:
I left the zips alone. Running
book3/make-zips.sh, or the pre-commit hook on your next commit, updatesre14.py,gmane.pyandgmodel.pyin the code zips and11-regex.htmlinbook3/zips/html.zip.Two things I noticed and left as they are:
gmane.py,'\Date: 'and'\Subject: 'look like they were meant to be'\nDate: 'and'\nSubject: '. As written,\Dmatches any non-digit and\Sany non-whitespace character, so the patterns also match headers likeX-Original-Date:andX-Subject:.code3/oauth.pyimportscgi, which Python 3.13 removed, so the Twitter samples stop at import on 3.13 and later. Switching tourllib.parse.parse_qsfixes it.I can send either fix as a separate PR if you want them.