commit 4ccbe411ff3320a09e21baa44280c357fd44df6e Author: Damian Johnson atagar@torproject.org Date: Sun Jan 27 12:41:50 2013 -0800
The min/max() functions can't accept None in python 3
In python 2:
>>> max(5, None) 5
In python 3:
>>> max(5, None) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unorderable types: NoneType() > int()
====================================================================== ERROR: test_comparison ---------------------------------------------------------------------- Traceback: File "/home/atagar/Desktop/stem/test/data/python3/test/unit/version.py", line 107, in test_comparison self.assert_version_is_equal("0.1.2", "0.1.2.0") File "/home/atagar/Desktop/stem/test/data/python3/test/unit/version.py", line 252, in assert_version_is_equal self.assertEqual(version1, version2) File "/usr/lib/python3.2/unittest/case.py", line 643, in assertEqual assertion_func(first, second, msg=msg) File "/usr/lib/python3.2/unittest/case.py", line 633, in _baseAssertEqual if not first == second: File "/home/atagar/Desktop/stem/test/data/python3/stem/version.py", line 214, in __eq__ return self._compare(other, lambda s, o: s == o) File "/home/atagar/Desktop/stem/test/data/python3/stem/version.py", line 197, in _compare my_version = max(0, self.__dict__[attr]) TypeError: unorderable types: NoneType() > int() --- stem/version.py | 10 ++++++++-- 1 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/stem/version.py b/stem/version.py index 46ed394..a7c816c 100644 --- a/stem/version.py +++ b/stem/version.py @@ -194,8 +194,14 @@ class Version(object): return False
for attr in ("major", "minor", "micro", "patch"): - my_version = max(0, self.__dict__[attr]) - other_version = max(0, other.__dict__[attr]) + my_version = getattr(self, attr) + other_version = getattr(other, attr) + + if my_version is None: + my_version = 0 + + if other_version is None: + other_version = 0
if my_version != other_version: return method(my_version, other_version)
tor-commits@lists.torproject.org