Commit 99c36c38 by Chris Jerdonek

Merge pull request #34 "Don't use `is` to compare integers"

From: https://github.com/alex/pystache/commit/b2ae206d68961b8aef568ceaa3dd1274150ef23e
Into: issue_34

Fixed a bug which caused the unit tests related to rendering zeroes to fail
when using PyPy.  Using "is" to compare integers relies on an implementation
of CPython.  The operator "==" should be used instead.
parents b01a1e00 b2ae206d
......@@ -166,7 +166,12 @@ class Template(object):
raw = self.view.get(tag_name, '')
# For methods with no return value
if not raw and raw is not 0:
#
# We use "==" rather than "is" to compare integers, as using "is" relies
# on an implementation detail of CPython. The test about rendering
# zeroes fails on PyPy when using "is".
# See issue #34: https://github.com/defunkt/pystache/issues/34
if not raw and raw != 0:
if tag_name == '.':
raw = self.view.context_list[0]
else:
......
......@@ -139,7 +139,11 @@ class View(object):
def __getitem__(self, attr):
val = self.get(attr, None)
if not val and val is not 0:
# We use "==" rather than "is" to compare integers, as using "is" relies
# on an implementation detail of CPython. The test about rendering
# zeroes fails on PyPy when using "is".
# See issue #34: https://github.com/defunkt/pystache/issues/34
if not val and val != 0:
raise KeyError("Key '%s' does not exist in View" % attr)
return val
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment