Allow use of newer python syntax with the format filter #289

Closed
wants to merge 3 commits into
from

Projects

None yet

3 participants

Allows the ability to use such newer syntax as {:,} for numeric separators amongst many others.

@berkerpeksag berkerpeksag commented on an outdated diff Jan 8, 2014
jinja2/filters.py
@@ -553,7 +553,17 @@ def do_format(value, *args, **kwargs):
if args and kwargs:
raise FilterArgumentError('can\'t handle positional and keyword '
'arguments at the same time')
- return soft_unicode(value) % (kwargs or args)
+ try:
+ ret = soft_unicode(value) % (kwargs or args)
+ if ret != value:
+ return ret
+ except TypeError, e:
berkerpeksag
berkerpeksag Jan 8, 2014 Contributor

Please use TypeError as e here (and use Exception as e in line 563). This brakes build on Python 3: https://travis-ci.org/mitsuhiko/jinja2/jobs/16600505

Owner

Not going to happen. This is a crude hack that's too easy to break :) If you want that a new filter would be required but why not use .format() then directly?

@mitsuhiko mitsuhiko closed this Jun 6, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment