diff options
author | cclauss <cclauss@bluewin.ch> | 2017-08-18 19:13:10 +0200 |
---|---|---|
committer | Jie Luo <anandolee@gmail.com> | 2017-08-18 10:13:10 -0700 |
commit | a04eb8c191e60171a9634cdd64715bd92e6769af (patch) | |
tree | 20a16b95494e92cc90ff72b245737d71a061f643 | |
parent | 1aa2c34387535d21aa15cd89fac3cf0169e9d63d (diff) | |
download | protobuf-a04eb8c191e60171a9634cdd64715bd92e6769af.tar.gz protobuf-a04eb8c191e60171a9634cdd64715bd92e6769af.tar.bz2 protobuf-a04eb8c191e60171a9634cdd64715bd92e6769af.zip |
Define cmp() for Python 3 (#3517)
* Define cmp() for Python 3
http://python-future.org/compatible_idioms.html?highlight=cmp#cmp
* Define cmp() for Python 3
http://python-future.org/compatible_idioms.html?highlight=cmp#cmp
-rwxr-xr-x | python/compatibility_tests/v2.5.0/tests/google/protobuf/internal/message_test.py | 5 | ||||
-rwxr-xr-x | python/google/protobuf/internal/message_test.py | 6 |
2 files changed, 10 insertions, 1 deletions
diff --git a/python/compatibility_tests/v2.5.0/tests/google/protobuf/internal/message_test.py b/python/compatibility_tests/v2.5.0/tests/google/protobuf/internal/message_test.py index 53e9d507..5053f035 100755 --- a/python/compatibility_tests/v2.5.0/tests/google/protobuf/internal/message_test.py +++ b/python/compatibility_tests/v2.5.0/tests/google/protobuf/internal/message_test.py @@ -55,6 +55,11 @@ from google.protobuf.internal import api_implementation from google.protobuf.internal import test_util from google.protobuf import message +try: + cmp # Python 2 +except NameError: + cmp = lambda(x, y): (x > y) - (x < y) # Python 3 + # Python pre-2.6 does not have isinf() or isnan() functions, so we have # to provide our own. def isnan(val): diff --git a/python/google/protobuf/internal/message_test.py b/python/google/protobuf/internal/message_test.py index f11bb6d6..dafc8077 100755 --- a/python/google/protobuf/internal/message_test.py +++ b/python/google/protobuf/internal/message_test.py @@ -53,9 +53,13 @@ import six import sys try: - import unittest2 as unittest #PY26 + import unittest2 as unittest # PY26 except ImportError: import unittest +try: + cmp # Python 2 +except NameError: + cmp = lambda(x, y): (x > y) - (x < y) # Python 3 from google.protobuf import map_unittest_pb2 from google.protobuf import unittest_pb2 |