Skip to content

Commit a579b04

Browse files
refactor: typehints and imports compatible to Python3.7 (#740)
1 parent e260227 commit a579b04

29 files changed

+54
-232
lines changed

src/dynamodb_encryption_sdk/delegated_keys/__init__.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,12 @@
1212
# language governing permissions and limitations under the License.
1313
"""Delegated keys."""
1414
import abc
15+
from typing import Dict, Optional, Text
1516

1617
import six
1718

1819
from dynamodb_encryption_sdk.identifiers import EncryptionKeyType # noqa pylint: disable=unused-import
1920

20-
try: # Python 3.5.0 and 3.5.1 have incompatible typing modules
21-
from typing import Dict, Optional, Text # noqa pylint: disable=unused-import
22-
except ImportError: # pragma: no cover
23-
# We only actually need these imports when running the mypy checks
24-
pass
25-
26-
2721
__all__ = ("DelegatedKey",)
2822

2923

src/dynamodb_encryption_sdk/delegated_keys/jce.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import logging
1717
import os
18+
from typing import Dict, Optional, Text
1819

1920
import attr
2021
import six
@@ -28,13 +29,6 @@
2829

2930
from . import DelegatedKey
3031

31-
try: # Python 3.5.0 and 3.5.1 have incompatible typing modules
32-
from typing import Dict, Optional, Text # noqa pylint: disable=unused-import
33-
except ImportError: # pragma: no cover
34-
# We only actually need these imports when running the mypy checks
35-
pass
36-
37-
3832
__all__ = ("JceNameLocalDelegatedKey",)
3933
_LOGGER = logging.getLogger(LOGGER_NAME)
4034

src/dynamodb_encryption_sdk/encrypted/__init__.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,6 @@
2121
from dynamodb_encryption_sdk.materials import CryptographicMaterials # noqa pylint: disable=unused-import
2222
from dynamodb_encryption_sdk.structures import AttributeActions, EncryptionContext
2323

24-
try: # Python 3.5.0 and 3.5.1 have incompatible typing modules
25-
from typing import Dict # noqa pylint: disable=unused-import
26-
except ImportError: # pragma: no cover
27-
# We only actually need these imports when running the mypy checks
28-
pass
29-
30-
3124
__all__ = ("CryptoConfig",)
3225

3326

src/dynamodb_encryption_sdk/encrypted/client.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# language governing permissions and limitations under the License.
1313
"""High-level helper class to provide a familiar interface to encrypted tables."""
1414
from functools import partial
15+
from typing import Any, Callable, Dict, Iterator, Optional
1516

1617
import attr
1718
import botocore
@@ -34,13 +35,6 @@
3435

3536
from .item import decrypt_dynamodb_item, decrypt_python_item, encrypt_dynamodb_item, encrypt_python_item
3637

37-
try: # Python 3.5.0 and 3.5.1 have incompatible typing modules
38-
from typing import Any, Callable, Dict, Iterator, Optional # noqa pylint: disable=unused-import
39-
except ImportError: # pragma: no cover
40-
# We only actually need these imports when running the mypy checks
41-
pass
42-
43-
4438
__all__ = ("EncryptedClient", "EncryptedPaginator")
4539

4640

src/dynamodb_encryption_sdk/encrypted/item.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,9 @@
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
1313
"""Top-level functions for encrypting and decrypting DynamoDB items."""
14-
try: # Python 3.5.0 and 3.5.1 have incompatible typing modules
15-
from dynamodb_encryption_sdk.internal import dynamodb_types # noqa pylint: disable=unused-import
16-
except ImportError: # pragma: no cover
17-
# We only actually need these imports when running the mypy checks
18-
pass
19-
2014
from dynamodb_encryption_sdk.exceptions import DecryptionError, EncryptionError
2115
from dynamodb_encryption_sdk.identifiers import CryptoAction
16+
from dynamodb_encryption_sdk.internal import dynamodb_types
2217
from dynamodb_encryption_sdk.internal.crypto.authentication import sign_item, verify_item_signature
2318
from dynamodb_encryption_sdk.internal.crypto.encryption import decrypt_attribute, encrypt_attribute
2419
from dynamodb_encryption_sdk.internal.formatting.material_description import (

src/dynamodb_encryption_sdk/encrypted/resource.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# language governing permissions and limitations under the License.
1313
"""High-level helper class to provide a familiar interface to encrypted tables."""
1414
from functools import partial
15+
from typing import Optional
1516

1617
import attr
1718
from boto3.resources.base import ServiceResource
@@ -29,13 +30,6 @@
2930
from .item import decrypt_python_item, encrypt_python_item
3031
from .table import EncryptedTable
3132

32-
try: # Python 3.5.0 and 3.5.1 have incompatible typing modules
33-
from typing import Optional # noqa pylint: disable=unused-import
34-
except ImportError: # pragma: no cover
35-
# We only actually need these imports when running the mypy checks
36-
pass
37-
38-
3933
__all__ = ("EncryptedResource", "EncryptedTablesCollectionManager")
4034

4135

src/dynamodb_encryption_sdk/encrypted/table.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# language governing permissions and limitations under the License.
1313
"""High-level helper class to provide a familiar interface to encrypted tables."""
1414
from functools import partial
15+
from typing import Optional
1516

1617
import attr
1718
from boto3.dynamodb.table import BatchWriter
@@ -30,13 +31,6 @@
3031
from .client import EncryptedClient
3132
from .item import decrypt_python_item, encrypt_python_item
3233

33-
try: # Python 3.5.0 and 3.5.1 have incompatible typing modules
34-
from typing import Optional # noqa pylint: disable=unused-import
35-
except ImportError: # pragma: no cover
36-
# We only actually need these imports when running the mypy checks
37-
pass
38-
39-
4034
__all__ = ("EncryptedTable",)
4135

4236

src/dynamodb_encryption_sdk/internal/crypto/authentication.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,19 @@
1616
No guarantee is provided on the modules and APIs within this
1717
namespace staying consistent. Directly reference at your own risk.
1818
"""
19+
from typing import Text
20+
1921
from cryptography.hazmat.backends import default_backend
2022
from cryptography.hazmat.primitives import hashes
2123

2224
from dynamodb_encryption_sdk.delegated_keys import DelegatedKey # noqa pylint: disable=unused-import
2325
from dynamodb_encryption_sdk.encrypted import CryptoConfig # noqa pylint: disable=unused-import
2426
from dynamodb_encryption_sdk.identifiers import CryptoAction
27+
from dynamodb_encryption_sdk.internal import dynamodb_types
2528
from dynamodb_encryption_sdk.internal.formatting.serialize.attribute import serialize_attribute
2629
from dynamodb_encryption_sdk.internal.identifiers import TEXT_ENCODING, SignatureValues, Tag
2730
from dynamodb_encryption_sdk.structures import AttributeActions # noqa pylint: disable=unused-import
2831

29-
try: # Python 3.5.0 and 3.5.1 have incompatible typing modules
30-
from typing import Text # noqa pylint: disable=unused-import
31-
32-
from dynamodb_encryption_sdk.internal import dynamodb_types # noqa pylint: disable=unused-import
33-
except ImportError: # pragma: no cover
34-
# We only actually need these imports when running the mypy checks
35-
pass
36-
37-
3832
__all__ = ("sign_item", "verify_item_signature")
3933

4034

src/dynamodb_encryption_sdk/internal/crypto/encryption.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,11 @@
1616
No guarantee is provided on the modules and APIs within this
1717
namespace staying consistent. Directly reference at your own risk.
1818
"""
19-
try: # Python 3.5.0 and 3.5.1 have incompatible typing modules
20-
from typing import Text # noqa pylint: disable=unused-import
2119

22-
from dynamodb_encryption_sdk.internal import dynamodb_types # noqa pylint: disable=unused-import
23-
except ImportError: # pragma: no cover
24-
# We only actually need these imports when running the mypy checks
25-
pass
20+
from typing import Text
2621

2722
from dynamodb_encryption_sdk.delegated_keys import DelegatedKey # noqa pylint: disable=unused-import
23+
from dynamodb_encryption_sdk.internal import dynamodb_types
2824
from dynamodb_encryption_sdk.internal.formatting.deserialize.attribute import deserialize_attribute
2925
from dynamodb_encryption_sdk.internal.formatting.serialize.attribute import serialize_attribute
3026
from dynamodb_encryption_sdk.internal.identifiers import Tag

src/dynamodb_encryption_sdk/internal/crypto/jce_bridge/authentication.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"""
1919
import abc
2020
import logging
21+
from typing import Any, Callable, Text
2122

2223
import attr
2324
import six
@@ -32,12 +33,6 @@
3233

3334
from .primitives import load_rsa_key
3435

35-
try: # Python 3.5.0 and 3.5.1 have incompatible typing modules
36-
from typing import Any, Callable, Text # noqa pylint: disable=unused-import
37-
except ImportError: # pragma: no cover
38-
# We only actually need these imports when running the mypy checks
39-
pass
40-
4136
__all__ = ("JavaAuthenticator", "JavaMac", "JavaSignature", "JAVA_AUTHENTICATOR")
4237
_LOGGER = logging.getLogger(LOGGER_NAME)
4338

src/dynamodb_encryption_sdk/internal/crypto/jce_bridge/primitives.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import abc
2020
import logging
2121
import os
22+
from typing import Any, Callable, Text
2223

2324
import attr
2425
import six
@@ -38,13 +39,6 @@
3839
from dynamodb_encryption_sdk.internal.identifiers import MinimumKeySizes
3940
from dynamodb_encryption_sdk.internal.validators import callable_validator
4041

41-
try: # Python 3.5.0 and 3.5.1 have incompatible typing modules
42-
from typing import Any, Callable, Text # noqa pylint: disable=unused-import
43-
except ImportError: # pragma: no cover
44-
# We only actually need these imports when running the mypy checks
45-
pass
46-
47-
4842
__all__ = (
4943
"JavaPadding",
5044
"SimplePadding",

src/dynamodb_encryption_sdk/internal/dynamodb_types.py

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,20 @@
55
namespace staying consistent. Directly reference at your own risk.
66
"""
77
# constant naming for types so pylint: disable=invalid-name
8-
try: # Python 3.5.0 and 3.5.1 have incompatible typing modules
9-
from typing import Any, AnyStr, ByteString, Dict, List, Text
8+
from typing import Any, AnyStr, ByteString, Dict, List, Text
109

11-
# https://github.com/aws/aws-dynamodb-encryption-python/issues/66
12-
ATTRIBUTE = Dict[Text, Any] # narrow this down
13-
ITEM = Dict[Text, ATTRIBUTE]
14-
RAW_ATTRIBUTE = ITEM
15-
NULL = bool # DynamoDB TypeSerializer converts none to {'NULL': True}
16-
BOOLEAN = bool
17-
# https://github.com/aws/aws-dynamodb-encryption-python/issues/66
18-
NUMBER = int # This misses long on Python 2...figure out something for this
19-
# https://github.com/aws/aws-dynamodb-encryption-python/issues/66
20-
STRING = AnyStr # can be unicode but should not be bytes
21-
BINARY = ByteString
22-
BINARY_ATTRIBUTE = Dict[Text, BINARY]
23-
SET = List # DynamoDB TypeSerializer converts sets into lists
24-
MAP = RAW_ATTRIBUTE
25-
LIST = List[RAW_ATTRIBUTE]
26-
except ImportError: # pragma: no cover
27-
# We only actually need these imports when running the mypy checks
28-
pass
10+
# https://github.com/aws/aws-dynamodb-encryption-python/issues/66
11+
ATTRIBUTE = Dict[Text, Any] # narrow this down
12+
ITEM = Dict[Text, ATTRIBUTE]
13+
RAW_ATTRIBUTE = ITEM
14+
NULL = bool # DynamoDB TypeSerializer converts none to {'NULL': True}
15+
BOOLEAN = bool
16+
# https://github.com/aws/aws-dynamodb-encryption-python/issues/66
17+
NUMBER = int # This misses long on Python 2...figure out something for this
18+
# https://github.com/aws/aws-dynamodb-encryption-python/issues/66
19+
STRING = AnyStr # can be unicode but should not be bytes
20+
BINARY = ByteString
21+
BINARY_ATTRIBUTE = Dict[Text, BINARY]
22+
SET = List # DynamoDB TypeSerializer converts sets into lists
23+
MAP = RAW_ATTRIBUTE
24+
LIST = List[RAW_ATTRIBUTE]

src/dynamodb_encryption_sdk/internal/formatting/deserialize/attribute.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,17 @@
2121
import logging
2222
import struct
2323
from decimal import Decimal
24+
from typing import Callable, Dict, List, Text, Union
2425

2526
from boto3.dynamodb.types import Binary
2627

2728
from dynamodb_encryption_sdk.exceptions import DeserializationError
2829
from dynamodb_encryption_sdk.identifiers import LOGGER_NAME
30+
from dynamodb_encryption_sdk.internal import dynamodb_types
2931
from dynamodb_encryption_sdk.internal.formatting.deserialize import decode_byte, decode_length, decode_tag, decode_value
3032
from dynamodb_encryption_sdk.internal.identifiers import TEXT_ENCODING, Tag, TagValues
3133
from dynamodb_encryption_sdk.internal.str_ops import to_str
3234

33-
try: # Python 3.5.0 and 3.5.1 have incompatible typing modules
34-
from typing import Callable, Dict, List, Text, Union # noqa pylint: disable=unused-import
35-
36-
from dynamodb_encryption_sdk.internal import dynamodb_types # noqa pylint: disable=unused-import,ungrouped-imports
37-
except ImportError: # pragma: no cover
38-
# We only actually need these imports when running the mypy checks
39-
pass
40-
41-
4235
__all__ = ("deserialize_attribute",)
4336
_LOGGER = logging.getLogger(LOGGER_NAME)
4437

src/dynamodb_encryption_sdk/internal/formatting/material_description.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,17 @@
1919
import io
2020
import logging
2121
import struct
22+
from typing import Dict, Text
2223

2324
from dynamodb_encryption_sdk.exceptions import InvalidMaterialDescriptionError, InvalidMaterialDescriptionVersionError
2425
from dynamodb_encryption_sdk.identifiers import LOGGER_NAME
26+
from dynamodb_encryption_sdk.internal import dynamodb_types
2527
from dynamodb_encryption_sdk.internal.identifiers import Tag
2628
from dynamodb_encryption_sdk.internal.str_ops import to_bytes, to_str
2729

2830
from .deserialize import decode_value, unpack_value
2931
from .serialize import encode_value
3032

31-
try: # Python 3.5.0 and 3.5.1 have incompatible typing modules
32-
from typing import Dict, Text # noqa pylint: disable=unused-import
33-
34-
from dynamodb_encryption_sdk.internal import dynamodb_types # noqa pylint: disable=unused-import
35-
except ImportError: # pragma: no cover
36-
# We only actually need these imports when running the mypy checks
37-
pass
38-
39-
4033
__all__ = ("serialize", "deserialize")
4134
_LOGGER = logging.getLogger(LOGGER_NAME)
4235
_MATERIAL_DESCRIPTION_VERSION = b"\00" * 4

src/dynamodb_encryption_sdk/internal/formatting/serialize/__init__.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,7 @@
1717
namespace staying consistent. Directly reference at your own risk.
1818
"""
1919
import struct
20-
21-
try: # Python 3.5.0 and 3.5.1 have incompatible typing modules
22-
from typing import Sized # noqa pylint: disable=unused-import
23-
except ImportError: # pragma: no cover
24-
# We only actually need these imports when running the mypy checks
25-
pass
20+
from typing import Sized
2621

2722
__all__ = ("encode_length", "encode_value")
2823

src/dynamodb_encryption_sdk/internal/formatting/serialize/attribute.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,17 @@
1818
"""
1919
import io
2020
import logging
21+
from typing import Callable
2122

2223
from boto3.dynamodb.types import DYNAMODB_CONTEXT, Binary
2324

2425
from dynamodb_encryption_sdk.exceptions import SerializationError
2526
from dynamodb_encryption_sdk.identifiers import LOGGER_NAME
27+
from dynamodb_encryption_sdk.internal import dynamodb_types
2628
from dynamodb_encryption_sdk.internal.formatting.serialize import encode_length, encode_value
2729
from dynamodb_encryption_sdk.internal.identifiers import Tag, TagValues
2830
from dynamodb_encryption_sdk.internal.str_ops import to_bytes
2931

30-
try: # Python 3.5.0 and 3.5.1 have incompatible typing modules
31-
from typing import Callable # noqa pylint: disable=unused-import
32-
33-
from dynamodb_encryption_sdk.internal import dynamodb_types # noqa pylint: disable=unused-import,ungrouped-imports
34-
except ImportError: # pragma: no cover
35-
# We only actually need these imports when running the mypy checks
36-
pass
37-
38-
3932
__all__ = ("serialize_attribute",)
4033
_LOGGER = logging.getLogger(LOGGER_NAME)
4134
_RESERVED = b"\x00"

src/dynamodb_encryption_sdk/internal/identifiers.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,7 @@
1717
namespace staying consistent. Directly reference at your own risk.
1818
"""
1919
from enum import Enum
20-
21-
try: # Python 3.5.0 and 3.5.1 have incompatible typing modules
22-
from typing import Optional, Text # noqa pylint: disable=unused-import
23-
except ImportError: # pragma: no cover
24-
# We only actually need these imports when running the mypy checks
25-
pass
20+
from typing import Optional, Text
2621

2722
__all__ = (
2823
"ReservedAttributes",

0 commit comments

Comments
 (0)