Skip to content

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

Closed

Description

@py-user
mannequin
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']

Activity

  1. py-user commented on Jul 8, 2011

    py-usermannequin
    MannequinAuthor
    >>> 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

  2. added
    stdlib
    type-feature
    on Jul 8, 2011
  3. SilentGhost commented on Jul 8, 2011

    SilentGhostmannequin
    Mannequin

    3.1 is in security fixes-only mode

  4. bitdancer commented on Jul 9, 2011

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

  5. merwok commented on Jul 11, 2011

    @merwok
    Member

    See 629200d880ea for answers.

  6. warsaw commented on Jul 11, 2011

    @warsaw
    Member

    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?

  7. warsaw commented on Mar 28, 2017

    @warsaw
    Member

    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

  8. added
    docs
    3.7 (EOL)
    and removed
    stdlib
    on Mar 28, 2017
  9. self-assigned this
    on Mar 28, 2017
  10. warsaw commented on Mar 28, 2017

    @warsaw
    Member

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

  11. transferred this issue fromon Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

3.7 (EOL)docstype-feature

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions