getnikola / plugins

Extra plugins for Nikola
https://plugins.getnikola.com/
MIT License
59 stars 95 forks source link

static_comments: compare to None not none in templates #273

Closed evgeni closed 6 years ago

felixfontein commented 6 years ago

For jinja2, it must be none and not None. No idea about Mako, though :)

evgeni commented 6 years ago

@felixfontein mako wants None, I did not test jinja, so amended the commit to only touch mako templates

felixfontein commented 6 years ago

Sounds good! I must admit that I haven't tested the Mako versions...

evgeni commented 6 years ago

I noticed ;)

felixfontein commented 6 years ago

Thanks for fixing this!

Kwpolska commented 6 years ago

I think None works in Jinja2 as well.

felixfontein commented 6 years ago

None works, but is None does not. At least, it used to not work...

felixfontein commented 6 years ago
import jinja2
print(jinja2.Environment().from_string('{% if None is none %}A{% else %}B{% endif %}').render())
print(jinja2.Environment().from_string('{% if None is None %}A{% else %}B{% endif %}').render())

This prints A and then dies with:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.6/site-packages/jinja2/environment.py", line 880, in from_string
    return cls.from_code(self, self.compile(source), globals, None)
  File "/usr/lib/python3.6/site-packages/jinja2/environment.py", line 591, in compile
    self.handle_exception(exc_info, source_hint=source_hint)
  File "/usr/lib/python3.6/site-packages/jinja2/environment.py", line 780, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/lib/python3.6/site-packages/jinja2/_compat.py", line 37, in reraise
    raise value.with_traceback(tb)
  File "<unknown>", line 1, in template
  File "/usr/lib/python3.6/site-packages/jinja2/environment.py", line 543, in _generate
    optimized=self.optimized)
  File "/usr/lib/python3.6/site-packages/jinja2/compiler.py", line 82, in generate
    generator.visit(node)
  File "/usr/lib/python3.6/site-packages/jinja2/visitor.py", line 38, in visit
    return f(node, *args, **kwargs)
  File "/usr/lib/python3.6/site-packages/jinja2/compiler.py", line 754, in visit_Template
    self.blockvisit(node.body, frame)
  File "/usr/lib/python3.6/site-packages/jinja2/compiler.py", line 378, in blockvisit
    self.visit(node, frame)
  File "/usr/lib/python3.6/site-packages/jinja2/visitor.py", line 38, in visit
    return f(node, *args, **kwargs)
  File "/usr/lib/python3.6/site-packages/jinja2/compiler.py", line 1157, in visit_If
    self.visit(node.test, if_frame)
  File "/usr/lib/python3.6/site-packages/jinja2/visitor.py", line 38, in visit
    return f(node, *args, **kwargs)
  File "/usr/lib/python3.6/site-packages/jinja2/compiler.py", line 70, in new_func
    return f(self, node, frame, **kwargs)
  File "/usr/lib/python3.6/site-packages/jinja2/compiler.py", line 1607, in visit_Test
    self.fail('no test named %r' % node.name, node.lineno)
  File "/usr/lib/python3.6/site-packages/jinja2/compiler.py", line 315, in fail
    raise TemplateAssertionError(msg, lineno, self.name, self.filename)
jinja2.exceptions.TemplateAssertionError: no test named 'None'