Skip to content
Myr

Python 2.6+ supports conditional expressions.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Cory Benfield · committed by Cory Benfield · parent 0d3b389 · Browse files · 1 file+7 added−24 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+7 added−24 removed

  • other:+7 added−24 removed

1 file+7 added−24 removed

modified:jinja2/compiler.py+7 added-24 removed
34 unmodified lines
35 'in': 'in',36 'notin': 'not in'37}3839try:40 exec('(0 if 0 else 0)')41except SyntaxError:42 have_condexpr = False43else:44 have_condexpr = True454639# what method to iterate over items do we want to use for dict iteration40# in generated code? on 2.x let's go with iteritems, on 3.x with items41if hasattr(dict, 'iteritems'):42 dict_item_iter = 'iteritems'
1513 unmodified lines
1556 self.write('environment.undefined(%r)' % ('the inline if-'1557 'expression on %s evaluated to false and '1558 'no else section was defined.' % self.position(node)))15591568 if not have_condexpr:1569 self.write('((')1570 self.visit(node.test, frame)1571 self.write(') and (')1572 self.visit(node.expr1, frame)1573 self.write(',) or (')1574 write_expr2()1575 self.write(',))[0]')1576 else:1577 self.write('(')1578 self.visit(node.expr1, frame)1579 self.write(' if ')1580 self.visit(node.test, frame)1581 self.write(' else ')1582 write_expr2()1583 self.write(')')1560 self.write('(')1561 self.visit(node.expr1, frame)1562 self.write(' if ')1563 self.visit(node.test, frame)1564 self.write(' else ')1565 write_expr2()1566 self.write(')')15671568 def visit_Call(self, node, frame, forward_caller=False):1569 if self.environment.sandboxed:1570 self.write('environment.call(context, ')
72 unmodified lines