Skip to content
Myr

Priority of `not` raised. It's now possible to write `not foo in bar`

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

as an alias to `foo not in bar` like in python. Previously the grammar required parentheses (`not (foo in bar)`) which was odd. --HG-- branch : trunk

authored by Armin Ronacher · committed by Armin Ronacher · parent 8de6f18 · Browse files · 6 files+21 added−8 removed
This commit

State

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

Diff stats

6 files+21 added−8 removed

  • tests:+6 added−0 removed
  • other:+15 added−8 removed

6 files+21 added−8 removed

modified:docs/_static/style.css+1 added
251 unmodified lines
252h3:hover > a.headerlink,253h4:hover > a.headerlink,254h5:hover > a.headerlink,255h6:hover > a.headerlink,256dt:hover > a.headerlink,257dt:hover > a.headerlink {258 visibility: visible;259}260
130 unmodified lines
modified:docs/cache_extension.py+2 added-2 removed
49 unmodified lines
50 # it in the cache.51 rv = self.environment.fragment_cache.get(key)52 if rv is None:53 return rv54 rv = caller()55 self.environment.fragment_cache.add(key, rv, timeout)54 rv = caller()55 self.environment.fragment_cache.add(key, rv, timeout)56 return rv
modified:jinja2/parser.py+8 added-6 removed
331 unmodified lines
332 return left333334 def parse_and(self):335 lineno = self.stream.current.lineno336 left = self.parse_compare()336 left = self.parse_not()337 while self.stream.skip_if('name:and'):338 right = self.parse_compare()338 right = self.parse_not()339 left = nodes.And(left, right, lineno=lineno)340 lineno = self.stream.current.lineno341 return left342343 def parse_not(self):344 if self.stream.current.test('name:not'):345 lineno = self.stream.next().lineno346 return nodes.Not(self.parse_not(), lineno=lineno)347 return self.parse_compare()348349 def parse_compare(self):350 lineno = self.stream.current.lineno351 expr = self.parse_add()352 ops = []
97 unmodified lines
450451 def parse_unary(self):452 token_type = self.stream.current.type453 lineno = self.stream.current.lineno448 if token_type == 'name' and self.stream.current.value == 'not':449 self.stream.next()450 node = self.parse_unary()451 return nodes.Not(node, lineno=lineno)454 if token_type == 'sub':455 self.stream.next()456 node = self.parse_unary()457 return nodes.Neg(node, lineno=lineno)
325 unmodified lines
modified:tests/test_syntax.py+6 added
187 unmodified lines
188189def test_string_concatenation(env):190 tmpl = env.from_string('{{ "foo" "bar" "baz" }}')191 assert tmpl.render() == 'foobarbaz'192193194def test_notin(env):195 bar = xrange(100)196 tmpl = env.from_string('''{{ not 42 in bar }}''')197 assert tmpl.render(bar=bar) == unicode(not 42 in bar)
modified:.hgignore+1 added
3 unmodified lines
4^docs/_build5^(build|dist|Jinja2\.egg-info)/6\.py[co]$7\.DS_Store$8^env/
modified:CHANGES+3 added
5 unmodified lines
6(codename unknown, release date yet unknown)78- Include statements can now be marked with ``ignore missing`` to skip9 non existing templates.10- Priority of `not` raised. It's now possible to write `not foo in bar`11 as an alias to `foo not in bar` like in python. Previously the grammar12 required parentheses (`not (foo in bar)`) which was odd.1314Version 2.1.115-------------16(Bugfix release)
84 unmodified lines