Skip to content

Commit ebfc733

Browse files
committed
Sort imports, simplify errors, require Python >= 3.6.
1 parent c4630dc commit ebfc733

File tree

8 files changed

+18
-19
lines changed

8 files changed

+18
-19
lines changed

ddbcereal/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
# limitations under the License.
1414

1515
from ddbcereal.deserializing import Deserializer
16+
from ddbcereal.exceptions import NumberInexact
1617
from ddbcereal.serializing import Serializer
1718
from ddbcereal.types import DateFormat, DynamoDBType, PythonNumber
18-
from ddbcereal.exceptions import NumberInexact
1919

2020
VERSION = 1, 0, 0
2121

ddbcereal/deserializing.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313
# limitations under the License.
1414

1515
from collections.abc import Set
16+
from decimal import Decimal
1617
from fractions import Fraction
17-
from typing import Any, Mapping, Union, ByteString, MutableMapping, Callable, Sequence
18+
from typing import (Any, ByteString, Callable, Mapping, MutableMapping,
19+
Sequence, Union)
1820

19-
from decimal import Decimal
21+
from ddbcereal import NumberInexact
2022
from ddbcereal.types import PythonNumber
2123

2224
DynamoDBTypeSymbol = str # Literal['B', 'BOOL', 'BS', 'N', 'NS', 'S', 'SS', 'L', 'M', 'NULL']
@@ -108,7 +110,10 @@ def deserialize_number_as_decimal(
108110

109111

110112
def deserialize_number_as_exact_int(serial_value: DynamoDBSerialValue) -> int:
111-
return int(serial_value)
113+
try:
114+
return int(serial_value)
115+
except ValueError:
116+
raise NumberInexact("Can't be represented exactly as an int.")
112117

113118

114119
def deserialize_number_as_int(serial_value: DynamoDBSerialValue) -> int:

ddbcereal/dispatching.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import MutableMapping, Callable
1+
from typing import Callable, MutableMapping
22

33

44
class TypedDispatchTable:

ddbcereal/exceptions.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
1-
class NumberRepresentationError(ValueError):
1+
class NumberInexact(ValueError):
22
pass
33

44

5-
class NumberInexact(NumberRepresentationError):
6-
pass
7-
8-
9-
class NumberRounded(NumberRepresentationError):
10-
pass
11-
12-
13-
class NumberNotAllowed(NumberRepresentationError):
5+
class NumberNotAllowed(ValueError):
146
pass
157

168

ddbcereal/serializing.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717
from collections.abc import Set
1818
from datetime import datetime
1919
from fractions import Fraction
20-
from typing import Any, Mapping, Union, MutableMapping, Callable
20+
from typing import Any, Callable, Mapping, MutableMapping, Union
2121

22-
from ddbcereal.exceptions import NumberInexact, NumberNotAllowed, StringNotAllowed
23-
from ddbcereal.types import DynamoDBType, DateFormat
22+
from ddbcereal.exceptions import (NumberInexact, NumberNotAllowed,
23+
StringNotAllowed)
24+
from ddbcereal.types import DateFormat, DynamoDBType
2425

2526
DynamoDBSerializable = Any
2627
DynamoDBDeserializable = Mapping[str, Any]

docs/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# -- Path setup --------------------------------------------------------------
88
import os
99
import sys
10+
1011
sys.path.append(os.path.abspath('..'))
1112

1213

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ license_files =
1818

1919
[options]
2020
packages = ddbcereal
21+
python_requires = >=3.6
2122

2223
[options.package_data]
2324
ddbcereal = py.typed

tests/test_deserializing.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
from ddbcereal.deserializing import Deserializer, PythonNumber
77

8-
98
NUM_SMALL_INT = {'N': '42'}
109
NUM_SMALL_NEG_INT = {'N': '-42'}
1110
NUM_NTSC_FILM_APPROX = {'N': '23.976023976023976023976023976023976024'}

0 commit comments

Comments
 (0)