Issue 12518: In string.Template it's impossible to transform delimiter in the derived class (original) (raw)

Created on 2011-07-08 00:36 by py.user, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (7)
msg140010 - (view) Author: py.user (py.user) * Date: 2011-07-08 00:36
>>> import string >>> class MyTemplate(string.Template): ... delimiter = '.' ... >>> MyTemplate.delimiter = 'x' >>> mt = MyTemplate('.field xfield') >>> mt.substitute(field=None) 'None xfield' >>> mt.delimiter 'x' >>> If I want to change the pattern string by any delimiter, I should create a new class for every delimiter I would change the delimiter either in the object or in the class at any time
msg140038 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2011-07-08 18:16
3.1 is in security fixes-only mode
msg140047 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2011-07-09 02:54
You are correct that this is a feature request as written. I think there is also a doc bug (the docs should probably mention that changing delimiter after class creation is a no-op). To add this feature the computation of the regex would need to be moved from the metaclass init to the object init. The question is, was doing this in a metaclass a design decision (perhaps a micro-optimization?), or a "cute trick" that turns out to cause unintuitive consequences? I think Barry was involved in adding the Template feature, so I'm adding him as nosy (I don't have a clone handy to check hg annotate).
msg140118 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-07-11 13:05
See 629200d880ea for answers.
msg140123 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2011-07-11 13:13
I don't know that anybody relies on the current behavior and computers are now a bazillion times faster than they were in 2004, so who needs that micro optimization any more?
msg290673 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2017-03-28 00:44
As this issue has been open for a long time, and I don't think it's worth changing the implementation, I am changing this to a documentation bug and will fix it along with the rewrites for bpo-19824 and bpo-20314
msg290718 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2017-03-28 14:02
New changeset 9f74deba784fc8781d13ed564f69c02ed7c331bb by Barry Warsaw in branch 'master': Improve the documentation for template strings (#856) https://github.com/python/cpython/commit/9f74deba784fc8781d13ed564f69c02ed7c331bb
History
Date User Action Args
2022-04-11 14:57:19 admin set github: 56727
2017-03-28 14:04:00 barry set status: open -> closedresolution: fixedstage: resolved
2017-03-28 14:02:09 barry set messages: +
2017-03-28 00:44:19 barry set assignee: barrymessages: + components: + Documentation, - Library (Lib)versions: + Python 3.7, - Python 3.3
2011-07-11 13:13:51 barry set messages: +
2011-07-11 13:05:12 eric.araujo set nosy: + eric.araujomessages: +
2011-07-09 02:54:58 r.david.murray set nosy: + barry, r.david.murraymessages: + versions: + Python 3.3, - Python 3.2
2011-07-08 18:16:58 SilentGhost set nosy: + SilentGhostmessages: + versions: + Python 3.2, - Python 3.1
2011-07-08 00:36:49 py.user create