Skip to content
6 changes: 5 additions & 1 deletion Lib/string.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class Template(metaclass=_TemplateMetaclass):
delimiter = '$'
idpattern = r'[_a-z][_a-z0-9]*'
braceidpattern = None
flags = _re.IGNORECASE
flags = _re.IGNORECASE | _re.ASCII
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add a comment here too, since a person reading the code may not notice the restored flag below.


def __init__(self, template):
self.template = template
Expand Down Expand Up @@ -157,6 +157,10 @@ def convert(mo):
return self.pattern.sub(convert, self.template)


# We use re.I | re.A when compiling Template.idpattern, but restore old flag
# for backward compatibility.
Template.flags = _re.IGNORECASE
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about:

We use re.I | re.A while compiling Template.idpattern in the metaclass above, but since
flags is part of the public API, we restore its original documented value for backward
compatibility.

?



########################################################################
# the Formatter class
Expand Down