New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
In string.Template it's impossible to transform delimiter in the derived class #56727
Comments
>>> 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 |
3.1 is in security fixes-only mode |
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). |
See 629200d880ea for answers. |
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? |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: