Skip to content

refactor: typehints and imports compatible to Python3.7 #740

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 30 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
e04f76c
Made typehints and imports compatible to Python3.7
khubaibalam2000 Sep 9, 2023
30367f3
import typings
khubaibalam2000 Sep 12, 2023
b4e40e3
removed-typehints-and-imports
khubaibalam2000 Sep 20, 2023
1c729ba
removed-typehints-and-imports
khubaibalam2000 Sep 22, 2023
8879ec3
fixed-bool-imports
khubaibalam2000 Sep 24, 2023
2a17535
fixed-isort-import-position-for-material-description
khubaibalam2000 Sep 24, 2023
a0d833b
fixed-import-positions-in-material_description
khubaibalam2000 Sep 24, 2023
cfc10fd
fixed-import-positions-in-material_description-of-struct
khubaibalam2000 Sep 24, 2023
e222c65
fixed-isort-errors-in-structures
khubaibalam2000 Sep 25, 2023
2aca491
fixed-positioning-of-imports-in-utils
khubaibalam2000 Sep 25, 2023
01b7ab7
fixed-import-positions-in-attributes
khubaibalam2000 Sep 25, 2023
d42bb97
fixed-position-of-imports-in-attributes-33
khubaibalam2000 Sep 25, 2023
c6fc474
fixed-position-of-imports-in-attributes-31
khubaibalam2000 Sep 25, 2023
61a5a16
fixed-position-of-imports-in-attribute-l30
khubaibalam2000 Sep 25, 2023
80a436e
fixed-position-of-imports-in-attribute-dynamo
khubaibalam2000 Sep 25, 2023
77f1890
fixed-import-positions
khubaibalam2000 Sep 25, 2023
bc55a8b
fixed-position-of-imports-in-primitives
khubaibalam2000 Sep 25, 2023
50c5d48
fixed-position-of-imports-in-primitives-L25
khubaibalam2000 Sep 25, 2023
b45298c
fixed-import-positions-in-files
khubaibalam2000 Sep 25, 2023
25cbae9
post-fixed-import-positions
khubaibalam2000 Sep 25, 2023
c22fe03
fixed-import-position-in-materials
khubaibalam2000 Sep 25, 2023
c1be115
fixed-import-position-in-materials-L18
khubaibalam2000 Sep 25, 2023
f8cad21
fixed-import-position-in-materials-L17
khubaibalam2000 Sep 25, 2023
4acc0ae
fixed-import-position-in-materials-L19
khubaibalam2000 Sep 25, 2023
7c5a785
fixed-import-position-in-materials-dynamodb
khubaibalam2000 Sep 25, 2023
420ce0c
fixed-mypy-imports
khubaibalam2000 Sep 26, 2023
ca5c9c4
fixed-import-positions-in-materials-init
khubaibalam2000 Sep 26, 2023
d948af0
fixed-import-position-in-materials-init
khubaibalam2000 Sep 26, 2023
7ac6b60
fixed-import-positions
khubaibalam2000 Sep 26, 2023
19c5045
Merge branch 'master' into master
lucasmcdonald3 Nov 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions src/dynamodb_encryption_sdk/delegated_keys/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,12 @@
# language governing permissions and limitations under the License.
"""Delegated keys."""
import abc
from typing import Dict, Optional, Text

import six

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

try: # Python 3.5.0 and 3.5.1 have incompatible typing modules
from typing import Dict, Optional, Text # noqa pylint: disable=unused-import
except ImportError: # pragma: no cover
# We only actually need these imports when running the mypy checks
pass


__all__ = ("DelegatedKey",)


Expand Down
8 changes: 1 addition & 7 deletions src/dynamodb_encryption_sdk/delegated_keys/jce.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import logging
import os
from typing import Dict, Optional, Text

import attr
import six
Expand All @@ -28,13 +29,6 @@

from . import DelegatedKey

try: # Python 3.5.0 and 3.5.1 have incompatible typing modules
from typing import Dict, Optional, Text # noqa pylint: disable=unused-import
except ImportError: # pragma: no cover
# We only actually need these imports when running the mypy checks
pass


__all__ = ("JceNameLocalDelegatedKey",)
_LOGGER = logging.getLogger(LOGGER_NAME)

Expand Down
7 changes: 0 additions & 7 deletions src/dynamodb_encryption_sdk/encrypted/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,6 @@
from dynamodb_encryption_sdk.materials import CryptographicMaterials # noqa pylint: disable=unused-import
from dynamodb_encryption_sdk.structures import AttributeActions, EncryptionContext

try: # Python 3.5.0 and 3.5.1 have incompatible typing modules
from typing import Dict # noqa pylint: disable=unused-import
except ImportError: # pragma: no cover
# We only actually need these imports when running the mypy checks
pass


__all__ = ("CryptoConfig",)


Expand Down
8 changes: 1 addition & 7 deletions src/dynamodb_encryption_sdk/encrypted/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# language governing permissions and limitations under the License.
"""High-level helper class to provide a familiar interface to encrypted tables."""
from functools import partial
from typing import Any, Callable, Dict, Iterator, Optional

import attr
import botocore
Expand All @@ -34,13 +35,6 @@

from .item import decrypt_dynamodb_item, decrypt_python_item, encrypt_dynamodb_item, encrypt_python_item

try: # Python 3.5.0 and 3.5.1 have incompatible typing modules
from typing import Any, Callable, Dict, Iterator, Optional # noqa pylint: disable=unused-import
except ImportError: # pragma: no cover
# We only actually need these imports when running the mypy checks
pass


__all__ = ("EncryptedClient", "EncryptedPaginator")


Expand Down
7 changes: 1 addition & 6 deletions src/dynamodb_encryption_sdk/encrypted/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,9 @@
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
"""Top-level functions for encrypting and decrypting DynamoDB items."""
try: # Python 3.5.0 and 3.5.1 have incompatible typing modules
from dynamodb_encryption_sdk.internal import dynamodb_types # noqa pylint: disable=unused-import
except ImportError: # pragma: no cover
# We only actually need these imports when running the mypy checks
pass

from dynamodb_encryption_sdk.exceptions import DecryptionError, EncryptionError
from dynamodb_encryption_sdk.identifiers import CryptoAction
from dynamodb_encryption_sdk.internal import dynamodb_types
from dynamodb_encryption_sdk.internal.crypto.authentication import sign_item, verify_item_signature
from dynamodb_encryption_sdk.internal.crypto.encryption import decrypt_attribute, encrypt_attribute
from dynamodb_encryption_sdk.internal.formatting.material_description import (
Expand Down
8 changes: 1 addition & 7 deletions src/dynamodb_encryption_sdk/encrypted/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# language governing permissions and limitations under the License.
"""High-level helper class to provide a familiar interface to encrypted tables."""
from functools import partial
from typing import Optional

import attr
from boto3.resources.base import ServiceResource
Expand All @@ -29,13 +30,6 @@
from .item import decrypt_python_item, encrypt_python_item
from .table import EncryptedTable

try: # Python 3.5.0 and 3.5.1 have incompatible typing modules
from typing import Optional # noqa pylint: disable=unused-import
except ImportError: # pragma: no cover
# We only actually need these imports when running the mypy checks
pass


__all__ = ("EncryptedResource", "EncryptedTablesCollectionManager")


Expand Down
8 changes: 1 addition & 7 deletions src/dynamodb_encryption_sdk/encrypted/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# language governing permissions and limitations under the License.
"""High-level helper class to provide a familiar interface to encrypted tables."""
from functools import partial
from typing import Optional

import attr
from boto3.dynamodb.table import BatchWriter
Expand All @@ -30,13 +31,6 @@
from .client import EncryptedClient
from .item import decrypt_python_item, encrypt_python_item

try: # Python 3.5.0 and 3.5.1 have incompatible typing modules
from typing import Optional # noqa pylint: disable=unused-import
except ImportError: # pragma: no cover
# We only actually need these imports when running the mypy checks
pass


__all__ = ("EncryptedTable",)


Expand Down
12 changes: 3 additions & 9 deletions src/dynamodb_encryption_sdk/internal/crypto/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,19 @@
No guarantee is provided on the modules and APIs within this
namespace staying consistent. Directly reference at your own risk.
"""
from typing import Text

from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes

from dynamodb_encryption_sdk.delegated_keys import DelegatedKey # noqa pylint: disable=unused-import
from dynamodb_encryption_sdk.encrypted import CryptoConfig # noqa pylint: disable=unused-import
from dynamodb_encryption_sdk.identifiers import CryptoAction
from dynamodb_encryption_sdk.internal import dynamodb_types
from dynamodb_encryption_sdk.internal.formatting.serialize.attribute import serialize_attribute
from dynamodb_encryption_sdk.internal.identifiers import TEXT_ENCODING, SignatureValues, Tag
from dynamodb_encryption_sdk.structures import AttributeActions # noqa pylint: disable=unused-import

try: # Python 3.5.0 and 3.5.1 have incompatible typing modules
from typing import Text # noqa pylint: disable=unused-import

from dynamodb_encryption_sdk.internal import dynamodb_types # noqa pylint: disable=unused-import
except ImportError: # pragma: no cover
# We only actually need these imports when running the mypy checks
pass


__all__ = ("sign_item", "verify_item_signature")


Expand Down
8 changes: 2 additions & 6 deletions src/dynamodb_encryption_sdk/internal/crypto/encryption.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,11 @@
No guarantee is provided on the modules and APIs within this
namespace staying consistent. Directly reference at your own risk.
"""
try: # Python 3.5.0 and 3.5.1 have incompatible typing modules
from typing import Text # noqa pylint: disable=unused-import

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

from dynamodb_encryption_sdk.delegated_keys import DelegatedKey # noqa pylint: disable=unused-import
from dynamodb_encryption_sdk.internal import dynamodb_types
from dynamodb_encryption_sdk.internal.formatting.deserialize.attribute import deserialize_attribute
from dynamodb_encryption_sdk.internal.formatting.serialize.attribute import serialize_attribute
from dynamodb_encryption_sdk.internal.identifiers import Tag
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"""
import abc
import logging
from typing import Any, Callable, Text

import attr
import six
Expand All @@ -32,12 +33,6 @@

from .primitives import load_rsa_key

try: # Python 3.5.0 and 3.5.1 have incompatible typing modules
from typing import Any, Callable, Text # noqa pylint: disable=unused-import
except ImportError: # pragma: no cover
# We only actually need these imports when running the mypy checks
pass

__all__ = ("JavaAuthenticator", "JavaMac", "JavaSignature", "JAVA_AUTHENTICATOR")
_LOGGER = logging.getLogger(LOGGER_NAME)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import abc
import logging
import os
from typing import Any, Callable, Text

import attr
import six
Expand All @@ -38,13 +39,6 @@
from dynamodb_encryption_sdk.internal.identifiers import MinimumKeySizes
from dynamodb_encryption_sdk.internal.validators import callable_validator

try: # Python 3.5.0 and 3.5.1 have incompatible typing modules
from typing import Any, Callable, Text # noqa pylint: disable=unused-import
except ImportError: # pragma: no cover
# We only actually need these imports when running the mypy checks
pass


__all__ = (
"JavaPadding",
"SimplePadding",
Expand Down
36 changes: 16 additions & 20 deletions src/dynamodb_encryption_sdk/internal/dynamodb_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,20 @@
namespace staying consistent. Directly reference at your own risk.
"""
# constant naming for types so pylint: disable=invalid-name
try: # Python 3.5.0 and 3.5.1 have incompatible typing modules
from typing import Any, AnyStr, ByteString, Dict, List, Text
from typing import Any, AnyStr, ByteString, Dict, List, Text

# https://github.com/aws/aws-dynamodb-encryption-python/issues/66
ATTRIBUTE = Dict[Text, Any] # narrow this down
ITEM = Dict[Text, ATTRIBUTE]
RAW_ATTRIBUTE = ITEM
NULL = bool # DynamoDB TypeSerializer converts none to {'NULL': True}
BOOLEAN = bool
# https://github.com/aws/aws-dynamodb-encryption-python/issues/66
NUMBER = int # This misses long on Python 2...figure out something for this
# https://github.com/aws/aws-dynamodb-encryption-python/issues/66
STRING = AnyStr # can be unicode but should not be bytes
BINARY = ByteString
BINARY_ATTRIBUTE = Dict[Text, BINARY]
SET = List # DynamoDB TypeSerializer converts sets into lists
MAP = RAW_ATTRIBUTE
LIST = List[RAW_ATTRIBUTE]
except ImportError: # pragma: no cover
# We only actually need these imports when running the mypy checks
pass
# https://github.com/aws/aws-dynamodb-encryption-python/issues/66
ATTRIBUTE = Dict[Text, Any] # narrow this down
ITEM = Dict[Text, ATTRIBUTE]
RAW_ATTRIBUTE = ITEM
NULL = bool # DynamoDB TypeSerializer converts none to {'NULL': True}
BOOLEAN = bool
# https://github.com/aws/aws-dynamodb-encryption-python/issues/66
NUMBER = int # This misses long on Python 2...figure out something for this
# https://github.com/aws/aws-dynamodb-encryption-python/issues/66
STRING = AnyStr # can be unicode but should not be bytes
BINARY = ByteString
BINARY_ATTRIBUTE = Dict[Text, BINARY]
SET = List # DynamoDB TypeSerializer converts sets into lists
MAP = RAW_ATTRIBUTE
LIST = List[RAW_ATTRIBUTE]
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,17 @@
import logging
import struct
from decimal import Decimal
from typing import Callable, Dict, List, Text, Union

from boto3.dynamodb.types import Binary

from dynamodb_encryption_sdk.exceptions import DeserializationError
from dynamodb_encryption_sdk.identifiers import LOGGER_NAME
from dynamodb_encryption_sdk.internal import dynamodb_types
from dynamodb_encryption_sdk.internal.formatting.deserialize import decode_byte, decode_length, decode_tag, decode_value
from dynamodb_encryption_sdk.internal.identifiers import TEXT_ENCODING, Tag, TagValues
from dynamodb_encryption_sdk.internal.str_ops import to_str

try: # Python 3.5.0 and 3.5.1 have incompatible typing modules
from typing import Callable, Dict, List, Text, Union # noqa pylint: disable=unused-import

from dynamodb_encryption_sdk.internal import dynamodb_types # noqa pylint: disable=unused-import,ungrouped-imports
except ImportError: # pragma: no cover
# We only actually need these imports when running the mypy checks
pass


__all__ = ("deserialize_attribute",)
_LOGGER = logging.getLogger(LOGGER_NAME)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,17 @@
import io
import logging
import struct
from typing import Dict, Text

from dynamodb_encryption_sdk.exceptions import InvalidMaterialDescriptionError, InvalidMaterialDescriptionVersionError
from dynamodb_encryption_sdk.identifiers import LOGGER_NAME
from dynamodb_encryption_sdk.internal import dynamodb_types
from dynamodb_encryption_sdk.internal.identifiers import Tag
from dynamodb_encryption_sdk.internal.str_ops import to_bytes, to_str

from .deserialize import decode_value, unpack_value
from .serialize import encode_value

try: # Python 3.5.0 and 3.5.1 have incompatible typing modules
from typing import Dict, Text # noqa pylint: disable=unused-import

from dynamodb_encryption_sdk.internal import dynamodb_types # noqa pylint: disable=unused-import
except ImportError: # pragma: no cover
# We only actually need these imports when running the mypy checks
pass


__all__ = ("serialize", "deserialize")
_LOGGER = logging.getLogger(LOGGER_NAME)
_MATERIAL_DESCRIPTION_VERSION = b"\00" * 4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@
namespace staying consistent. Directly reference at your own risk.
"""
import struct

try: # Python 3.5.0 and 3.5.1 have incompatible typing modules
from typing import Sized # noqa pylint: disable=unused-import
except ImportError: # pragma: no cover
# We only actually need these imports when running the mypy checks
pass
from typing import Sized

__all__ = ("encode_length", "encode_value")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,17 @@
"""
import io
import logging
from typing import Callable

from boto3.dynamodb.types import DYNAMODB_CONTEXT, Binary

from dynamodb_encryption_sdk.exceptions import SerializationError
from dynamodb_encryption_sdk.identifiers import LOGGER_NAME
from dynamodb_encryption_sdk.internal import dynamodb_types
from dynamodb_encryption_sdk.internal.formatting.serialize import encode_length, encode_value
from dynamodb_encryption_sdk.internal.identifiers import Tag, TagValues
from dynamodb_encryption_sdk.internal.str_ops import to_bytes

try: # Python 3.5.0 and 3.5.1 have incompatible typing modules
from typing import Callable # noqa pylint: disable=unused-import

from dynamodb_encryption_sdk.internal import dynamodb_types # noqa pylint: disable=unused-import,ungrouped-imports
except ImportError: # pragma: no cover
# We only actually need these imports when running the mypy checks
pass


__all__ = ("serialize_attribute",)
_LOGGER = logging.getLogger(LOGGER_NAME)
_RESERVED = b"\x00"
Expand Down
7 changes: 1 addition & 6 deletions src/dynamodb_encryption_sdk/internal/identifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@
namespace staying consistent. Directly reference at your own risk.
"""
from enum import Enum

try: # Python 3.5.0 and 3.5.1 have incompatible typing modules
from typing import Optional, Text # noqa pylint: disable=unused-import
except ImportError: # pragma: no cover
# We only actually need these imports when running the mypy checks
pass
from typing import Optional, Text

__all__ = (
"ReservedAttributes",
Expand Down
Loading