Issue 31669: string.Template: code, docs and PEP all disagree on definition of identifier
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) * ![]() |
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) * ![]() |
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:53 | admin | set | github: 75850 |
| 2017-10-03 15:07:13 | barry | set | messages: + msg303625 |
| 2017-10-03 14:58:33 | tjollans | set | messages:
+ 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:41 | barry | set | nosy:
+ barry |
| 2017-10-03 13:17:15 | serhiy.storchaka | set | status: open -> closed nosy:
+ serhiy.storchaka resolution: not a bug |
| 2017-10-03 12:50:19 | methane | set | superseder: string.Template should use re.ASCII flag |
| 2017-10-03 06:02:28 | tjollans | create | |
