New submission from Dmitry Kazakov:
I came across this piece of code in Lib/string.py:146:
# We use this idiom instead of str() because the latter will
# fail if val is a Unicode containing non-ASCII characters.
return '%s' % (mapping[named],)
This seems vestigial. I think it'd be appropriate to "fix" the string.Template
by replacing the printf-style formatting with newer str.format everywhere in
the Template's source. The obvious advantage is that by tweaking some regexes
we'll make possible formatting using the following syntax
${thing.attribute_or_key}
by dropping to the str.format
return '{named}'.format(**mapping) # <-- new version
It'd also make sense to use the str.format_map to implement the
Template.safe_substitute.
Borrowing some ideas from issue1198569, we can then expose an additional
attribute called Template.bracepattern to allow programmers use the
str.format-based substitution extensively:
$name
${name.thing}
${name.thing: >16}
This change won't break any existing code.
But I'm not exactly sure string.Template should be in Python 3 at all. It's one
of the least used features and PEP 292 states it was added as an alternative to
%-based substitution. I think it'd be deprecated and removed from the standard
library.
So what's the resolution? Should we fix it or deprecate it or both?
----------
components: Library (Lib)
messages: 244262
nosy: vlth
priority: normal
severity: normal
status: open
title: string.Template should be using str.format and/or deprecated
type: enhancement
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue24309>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com