adapt compat.py style to the one from requests

This commit is contained in:
Christian Stade-Schuldt
2017-05-25 12:14:58 -07:00
parent 2b60e817ea
commit 46b7e369b3
2 changed files with 23 additions and 8 deletions
+21 -7
View File
@@ -6,16 +6,30 @@ maya.compat
This module handles import compatibility issues between Python 2 and
Python 3.
"""
import sys
if sys.version_info < (3, 0):
_PY3 = False
else:
_PY3 = True
# -------
# Pythons
# -------
try:
# Syntax sugar.
_ver = sys.version_info
#: Python 2.x?
is_py2 = (_ver[0] == 2)
#: Python 3.x?
is_py3 = (_ver[0] == 3)
# ---------
# Specifics
# ---------
if is_py2:
cmp = cmp
except NameError:
elif is_py3:
def cmp(a, b):
"""
Compare two objects.
@@ -38,7 +52,7 @@ def comparable(klass):
relying on C{__cmp__} to implement their comparisons.
"""
# On Python 2, __cmp__ will just work, so no need to add extra methods:
if not _PY3:
if not is_py3:
return klass
def __eq__(self, other):
+2 -1
View File
@@ -12,6 +12,7 @@ import email.utils
import time
from datetime import timedelta, datetime as Datetime
import functools
import pytz
import humanize
import dateparser
@@ -506,7 +507,7 @@ class MayaInterval(object):
@staticmethod
def flatten(ii):
return reduce(lambda reduced, i: (
return functools.reduce(lambda reduced, i: (
(reduced[:-1] + i.combine(reduced[-1]))
if reduced else [i]
), sorted(ii), [])