]> git.ipfire.org Git - thirdparty/jinja.git/commitdiff
Fixed warnings if Python is run with -3.
authorArmin Ronacher <armin.ronacher@active-4.com>
Wed, 7 Aug 2013 11:48:37 +0000 (12:48 +0100)
committerArmin Ronacher <armin.ronacher@active-4.com>
Wed, 7 Aug 2013 11:48:37 +0000 (12:48 +0100)
This also adds proper hashing and comparision support to
undefined objects.

This fixes #224

CHANGES
jinja2/nodes.py
jinja2/runtime.py

diff --git a/CHANGES b/CHANGES
index 1c7caf4b27b96cd6e6a83fc1846f9500b527d013..01afc4ea298f3067828e81848213fc8e1448c961 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -10,6 +10,9 @@ Version 2.7.1
 - Fixed lack of Python 3 support for bytecode caches.
 - Reverted support for defining blocks in included templates as this
   broke existing templates for users.
+- Fixed some warnings with hashing of undefineds and nodes if Python
+  is run with warnings for Python 3.
+- Added support for properly hashing undefined objects.
 
 Version 2.7
 -----------
index 81fafb8b8d0a7f9efafc4d582cc3ef0139bd7dbb..c5697e6b5ec3737a0e43656c883340656c4544d3 100644 (file)
@@ -232,6 +232,9 @@ class Node(with_metaclass(NodeType, object)):
     def __ne__(self, other):
         return not self.__eq__(other)
 
+    # Restore Python 2 hashing behavior on Python 3
+    __hash__ = object.__hash__
+
     def __repr__(self):
         return '%s(%s)' % (
             self.__class__.__name__,
index d27ca537cd7259872b54d96851a3b497443fdd0d..7791c645afe997d45e75355fddad384f9d525d94 100644 (file)
@@ -497,6 +497,15 @@ class Undefined(object):
     __float__ = __complex__ = __pow__ = __rpow__ = \
         _fail_with_undefined_error
 
+    def __eq__(self, other):
+        return type(self) is type(other)
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
+    def __hash__(self):
+        return id(type(self))
+
     def __str__(self):
         return u''
 
@@ -563,7 +572,8 @@ class StrictUndefined(Undefined):
     """
     __slots__ = ()
     __iter__ = __str__ = __len__ = __nonzero__ = __eq__ = \
-        __ne__ = __bool__ = Undefined._fail_with_undefined_error
+        __ne__ = __bool__ = __hash__ = \
+        Undefined._fail_with_undefined_error
 
 
 # remove remaining slots attributes, after the metaclass did the magic they