Skip to content
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

Closed
py-user mannequin opened this issue Jul 8, 2011 · 7 comments
Closed

In string.Template it's impossible to transform delimiter in the derived class #56727

py-user mannequin opened this issue Jul 8, 2011 · 7 comments
Assignees
Labels
3.7 (EOL) end of life docs Documentation in the Doc dir type-feature A feature request or enhancement

Comments

@py-user
Copy link
Mannequin

py-user mannequin commented Jul 8, 2011

BPO 12518
Nosy @warsaw, @merwok, @bitdancer, @py-user

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:

assignee = 'https://github.com/warsaw'
closed_at = <Date 2017-03-28.14:04:00.346>
created_at = <Date 2011-07-08.00:36:49.067>
labels = ['type-feature', '3.7', 'docs']
title = "In string.Template it's impossible to transform delimiter in the derived class"
updated_at = <Date 2017-03-28.14:04:00.345>
user = 'https://github.com/py-user'

bugs.python.org fields:

activity = <Date 2017-03-28.14:04:00.345>
actor = 'barry'
assignee = 'barry'
closed = True
closed_date = <Date 2017-03-28.14:04:00.346>
closer = 'barry'
components = ['Documentation']
creation = <Date 2011-07-08.00:36:49.067>
creator = 'py.user'
dependencies = []
files = []
hgrepos = []
issue_num = 12518
keywords = []
message_count = 7.0
messages = ['140010', '140038', '140047', '140118', '140123', '290673', '290718']
nosy_count = 5.0
nosy_names = ['barry', 'eric.araujo', 'r.david.murray', 'SilentGhost', 'py.user']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue12518'
versions = ['Python 3.7']

@py-user
Copy link
Mannequin Author

py-user mannequin commented Jul 8, 2011

>>> 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

@py-user py-user mannequin added stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Jul 8, 2011
@SilentGhost
Copy link
Mannequin

SilentGhost mannequin commented Jul 8, 2011

3.1 is in security fixes-only mode

@bitdancer
Copy link
Member

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).

@merwok
Copy link
Member

merwok commented Jul 11, 2011

See 629200d880ea for answers.

@warsaw
Copy link
Member

warsaw commented Jul 11, 2011

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?

@warsaw
Copy link
Member

warsaw commented Mar 28, 2017

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

@warsaw warsaw added docs Documentation in the Doc dir 3.7 (EOL) end of life and removed stdlib Python modules in the Lib dir labels Mar 28, 2017
@warsaw warsaw self-assigned this Mar 28, 2017
@warsaw
Copy link
Member

warsaw commented Mar 28, 2017

New changeset 9f74deb by Barry Warsaw in branch 'master':
Improve the documentation for template strings (#856)
9f74deb

@warsaw warsaw closed this as completed Mar 28, 2017
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.7 (EOL) end of life docs Documentation in the Doc dir type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

3 participants