should fix some import issues with python 2.7

This commit is contained in:
Mark Chackerian 2018-07-16 17:20:49 -04:00
parent de050fa6db
commit 0fdc2ca3eb
2 changed files with 9 additions and 3 deletions

View File

@ -1,4 +1,6 @@
import decimal
from __future__ import absolute_import
from decimal import Decimal as _Decimal
from graphql.language import ast
@ -11,7 +13,9 @@ class Decimal(Scalar):
"""
@staticmethod
def serialize(dec):
assert isinstance(dec, decimal.Decimal), (
if isinstance(dec, str):
dec = _Decimal(dec)
assert isinstance(dec, _Decimal), (
'Received not compatible Decimal "{}"'.format(repr(dec))
)
return str(dec)
@ -24,6 +28,6 @@ class Decimal(Scalar):
@staticmethod
def parse_value(value):
try:
return decimal.Decimal(value)
return _Decimal(value)
except ValueError:
return None

View File

@ -21,6 +21,7 @@ def test_decimal_string_query():
assert result.data == {
'decimal': str(decimal_value)
}
assert decimal.Decimal(result.data['decimal']) == decimal_value
def test_decimal_string_query_variable():
@ -34,6 +35,7 @@ def test_decimal_string_query_variable():
assert result.data == {
'decimal': str(decimal_value)
}
assert decimal.Decimal(result.data['decimal']) == decimal_value
def test_bad_decimal_query():