-
- Notifications
You must be signed in to change notification settings - Fork 33.4k
bpo-31672: string: Use re.A | re.I flag for identifier pattern #3872
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
Changes from 4 commits
c43ec46 3862b33 586ef34 8b2f429 32b765b 1e4bb62 961a206 File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| | @@ -755,8 +755,18 @@ attributes: | |
| | ||
| * *idpattern* -- This is the regular expression describing the pattern for | ||
| non-braced placeholders. The default value is the regular expression | ||
| ``[_a-z][_a-z0-9]*``. If this is given and *braceidpattern* is ``None`` | ||
| this pattern will also apply to braced placeholders. | ||
| ``(?-i:[_a-zA-Z][_a-zA-Z0-9]*)``. Since default *flags* is | ||
| ``re.IGNORECASE``, ``[a-z]``Without local flag ``-i``, is used to avoid to match with non ASCII characters. | ||
| If this is given and *braceidpattern* is | ||
| ``None`` this pattern will also apply to braced placeholders. | ||
| | ||
| .. note:: | ||
| | ||
| Default *flags* is ``re.IGNORECASE``. So the pattern ``[a-z]`` can match | ||
| with some non ASCII characters. That's why We use local ``-i`` flag here. | ||
| ||
| | ||
| When overrinding this class, please consider overriding *flags* with ``0`` | ||
| or ``re.IGNORECASE | re.ASCII``. | ||
| ||
| | ||
| .. versionchanged:: 3.7 | ||
| *braceidpattern* can be used to define separate patterns used inside and | ||
| | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| | @@ -270,6 +270,10 @@ def test_invalid_placeholders(self): | |
| raises(ValueError, s.substitute, dict(who='tim')) | ||
| s = Template('$who likes $100') | ||
| raises(ValueError, s.substitute, dict(who='tim')) | ||
| # Template.idpattern should match to only ASCII characters. | ||
| # https://bugs.python.org/issue31672 | ||
| s = Template("$who likes $ı") # (0x131, DOTLESS I) | ||
| ||
| raises(ValueError, s.substitute, dict(who='tim')) | ||
| | ||
| def test_idpattern_override(self): | ||
| class PathPattern(Template): | ||
| | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| ``idpattern`` in ``string.Template`` matched some non ASCII characters. Now | ||
| it uses ``-i`` regular expression local flag to avoid non ASCII characters. | ||
| ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be a space before the
W, but I also feel like the sentence starting with "Since default..." should just be moved to, and consolidated with, thenote::section that just follows.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I missed removing this sentence after writing note section.