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.safe_substitute hard-wires "braces" as {}
Type: behavior Stage:
Components: Library (Lib) Versions: Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Adam.Kellas, barry, eric.araujo, georg.brandl, sam.kimbrel
Priority: normal Keywords:

Created on 2013-01-29 21:30 by Adam.Kellas, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (5)
msg180949 - (view) Author: Adam Kellas (Adam.Kellas) Date: 2013-01-29 21:30
If you use safe_substitute and try to use a variable reference style other than ${foo}, you will find that it assumes ${foo} style. In particular, when evaluating $[foo] (square braces) and 'foo' is not defined, safe_substitute will put the string back together using ${foo} (curly braces).

See <http://stackoverflow.com/questions/14573230/pythons-string-template-changes-brackets-when-variable-is-unset> for details and test case.
msg180958 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2013-01-29 23:12
See PEP 292 and the section titled "Why `$' and Braces?"

http://www.python.org/dev/peps/pep-0292/
msg181093 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2013-02-01 19:03
Barry, I read that passage in the PEP to explain why the default style uses ${}, but the bug here is about a Template class with an overriden placeholder pattern.
msg216227 - (view) Author: Sam Kimbrel (sam.kimbrel) * Date: 2014-04-14 21:54
Florent Xicluna already fixed this in r84888 for 3.2+; I've tested that the patch applies cleanly to 2.7 and tests pass. Someone with the commit bit should transplant that commit into 2.7 as it does not change the public API to this module.
msg228706 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2014-10-06 15:38
Done in 8a98ee6baa1e. Thanks!
History
Date User Action Args
2022-04-11 14:57:41adminsetgithub: 61280
2014-10-06 15:38:42georg.brandlsetstatus: open -> closed
resolution: fixed
2014-10-06 15:38:35georg.brandlsetnosy: + georg.brandl
messages: + msg228706
2014-04-14 21:54:01sam.kimbrelsetnosy: + sam.kimbrel
messages: + msg216227
2013-02-01 19:03:09eric.araujosetnosy: + eric.araujo
messages: + msg181093
2013-01-29 23:12:26barrysetmessages: + msg180958
2013-01-29 22:15:25r.david.murraysetnosy: + barry
2013-01-29 21:30:46Adam.Kellascreate