From c8a7ad36def33b13e6b3f78c34a4e05cbce1e960 Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Mon, 23 Feb 2015 00:22:00 +0100 Subject: [PATCH] Compatibility with PyPy On PyPy, dict.__reversed__ exists and raises a TypeError, on CPython, it doesn't. However, reversed({}) behaves the same on both sides. --- vdirsyncer/utils/vobject.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/vdirsyncer/utils/vobject.py b/vdirsyncer/utils/vobject.py index ea428f0..5453ae8 100644 --- a/vdirsyncer/utils/vobject.py +++ b/vdirsyncer/utils/vobject.py @@ -40,8 +40,12 @@ del _process_properties # # This basically checks whether the superclass of all icalendar classes has a # method from OrderedDict. -ICALENDAR_ORIGINAL_ORDER_SUPPORT = \ - hasattr(icalendar.caselessdict.CaselessDict, '__reversed__') +try: + reversed(icalendar.caselessdict.CaselessDict()) +except TypeError: + ICALENDAR_ORIGINAL_ORDER_SUPPORT = False +else: + ICALENDAR_ORIGINAL_ORDER_SUPPORT = True class Item(object):