diff options
author | Gunnar Aastrand Grimnes <gromgull@gmail.com> | 2013-03-09 10:29:04 +0100 |
---|---|---|
committer | Gunnar Aastrand Grimnes <gromgull@gmail.com> | 2013-03-09 10:29:04 +0100 |
commit | fee948b21df67374da13e7edcf23b8d4b369b2f5 (patch) | |
tree | 25d40a50b2832e907dfeff0aaceae65241725904 /rdflib/compat.py | |
parent | bd12b7d01a9824954c374eba81522ebbf103b7e0 (diff) | |
download | rdflib-fee948b21df67374da13e7edcf23b8d4b369b2f5.tar.gz |
special comparison for decimal/floats in py<2.7. fixes #254
Diffstat (limited to 'rdflib/compat.py')
-rw-r--r-- | rdflib/compat.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/rdflib/compat.py b/rdflib/compat.py index b0616395..6c714894 100644 --- a/rdflib/compat.py +++ b/rdflib/compat.py @@ -2,3 +2,24 @@ # code to simplify supporting older python versions # + +import sys + +from decimal import Decimal + +if sys.version_info[:2] < (2, 7): + + # Pre-2.7 decimal and float did not compare correctly + + def numeric_greater(a, b): + if isinstance(a, Decimal) and isinstance(b, float): + return float(a) > b + elif isinstance(a, float) and isinstance(b, Decimal): + return a > float(b) + else: + return a > b + +else: + + def numeric_greater(a, b): + return a > b |