[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [stem/master] Python 3 can't do comparison with other types



commit b96f434623cd829dc8e143e1e685167facad4e22
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sun Jan 27 12:51:57 2013 -0800

    Python 3 can't do comparison with other types
    
    Another change in python 2 => 3 is that comparison ('<' and '>') can no longer
    work with None, ints, and other types...
    
    In python 2:
    
    >>> 5 > None
    True
    
    In python 3:
    
    >>> 5 > None
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: unorderable types: int() > NoneType()
    
    I expected the 'unorderable types' error would cause it to use the Version's
    comparison function but evidently that's not the case. Rather, when using
    python 3 callers need to check the values' type first (there's nothing we can
    do to make the comparison work). Personally I think that this is pretty stupid,
    but that's the workaround done by python devs on...
    
    http://bugs.python.org/issue13545
    
    Oh well. Dropping the test that comparison with None and ints work.
    
    ======================================================================
    ERROR: test_nonversion_comparison
    ----------------------------------------------------------------------
    Traceback:
      File "/home/atagar/Desktop/stem/test/data/python3/test/unit/version.py", line 125, in test_nonversion_comparison
        self.assertTrue(test_version > None)
    TypeError: unorderable types: Version() > NoneType()
    
    ----------------------------------------------------------------------
    Ran 9 tests in 0.043s
---
 test/unit/version.py |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/test/unit/version.py b/test/unit/version.py
index eee4d0c..068492a 100644
--- a/test/unit/version.py
+++ b/test/unit/version.py
@@ -118,14 +118,14 @@ class TestVersion(unittest.TestCase):
   def test_nonversion_comparison(self):
     """
     Checks that we can be compared with other types.
+
+    In python 3 on only equality comparisons work, greater than and less than
+    comparisons result in a TypeError.
     """
 
     test_version = Version("0.1.2.3")
     self.assertNotEqual(test_version, None)
-    self.assertTrue(test_version > None)
-
     self.assertNotEqual(test_version, 5)
-    self.assertTrue(test_version > 5)
 
   def test_string(self):
     """



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits