This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: string.Template: code, docs and PEP all disagree on definition of identifier
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder: string.Template should use re.ASCII flag
View: 31672
Assigned To: Nosy List: barry, serhiy.storchaka, tjollans
Priority: normal Keywords:

Created on 2017-10-03 06:02 by tjollans, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (4)
msg303577 - (view) Author: Thomas Jollans (tjollans) Date: 2017-10-03 06:02
string.Template matches a $identifier with the regex [_a-z][_a-z0-9]* and re.IGNORECASE. This matches S, ſ and s, but not ß. https://github.com/python/cpython/blob/master/Lib/string.py#L78 (this code came up on python-dev)

The docs specify "any case-insensitive ASCII alphanumeric string (including underscores) that starts with an underscore or ASCII letter.". This includes S and s, but neither ſ nor ß. https://docs.python.org/3/library/string.html#template-strings

The docs refer to PEP 292, which specifies "By default, 'identifier' must spell a Python identifier [...]" This includes S, ſ, s and ß. https://www.python.org/dev/peps/pep-0292/

It's not entirely clear what the correct behaviour is (probably accepting any Python identifier). In any case, the current behaviour of string.Template is a bit silly, but changing it might break stuff.
msg303614 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-10-03 13:17
There is no contradiction. PEP 292 means Python 2 identifiers. Python 3 documentation was changed according to changing the definition of Python identifiers (see issue24351).
msg303623 - (view) Author: Thomas Jollans (tjollans) Date: 2017-10-03 14:58
Should the PEP be clarified?
msg303625 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2017-10-03 15:07
PEPs aren't really intended to be ongoing specs, keeping up with implementation changes.  The documentation is pretty clear in defining identifiers as "any case-insensitive ASCII alphanumeric string (including underscores) that starts with an underscore or ASCII letter".
History
Date User Action Args
2022-04-11 14:58:53adminsetgithub: 75850
2017-10-03 15:07:13barrysetmessages: + msg303625
2017-10-03 14:58:33tjollanssetmessages: + msg303623
title: string.Template: cods, docs and PEP all disagree on definition of identifier -> string.Template: code, docs and PEP all disagree on definition of identifier
2017-10-03 14:26:41barrysetnosy: + barry
2017-10-03 13:17:15serhiy.storchakasetstatus: open -> closed

nosy: + serhiy.storchaka
messages: + msg303614

resolution: not a bug
stage: resolved
2017-10-03 12:50:19methanesetsuperseder: string.Template should use re.ASCII flag
2017-10-03 06:02:28tjollanscreate