From 46b7e369b3a90beaba902b6d604d4eed5e232332 Mon Sep 17 00:00:00 2001 From: Christian Stade-Schuldt Date: Thu, 25 May 2017 12:14:58 -0700 Subject: [PATCH] adapt compat.py style to the one from requests --- compat.py | 28 +++++++++++++++++++++------- maya.py | 3 ++- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/compat.py b/compat.py index 29e1a99..b855720 100644 --- a/compat.py +++ b/compat.py @@ -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): diff --git a/maya.py b/maya.py index 513a8e2..6455a2a 100644 --- a/maya.py +++ b/maya.py @@ -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), [])