From d1ece6e9216f2278b35d73eee49555d26a18d981 Mon Sep 17 00:00:00 2001 From: Hayden Baker Date: Wed, 26 Feb 2025 08:29:32 -0800 Subject: [PATCH 1/9] Add ruff lint rule - I --- .../aws-event-stream/tests/unit/_private/__init__.py | 3 +-- .../tests/unit/_private/test_deserializers.py | 7 +++---- .../tests/unit/_private/test_serializers.py | 5 ++--- packages/aws-event-stream/tests/unit/test_events.py | 3 +-- packages/smithy-core/tests/unit/aio/test_types.py | 1 - packages/smithy-core/tests/unit/test_documents.py | 1 - packages/smithy-core/tests/unit/test_identity.py | 1 - packages/smithy-core/tests/unit/test_retries.py | 1 - packages/smithy-core/tests/unit/test_schemas.py | 1 - packages/smithy-core/tests/unit/test_shapes.py | 1 - packages/smithy-core/tests/unit/test_types.py | 1 - packages/smithy-core/tests/unit/test_uri.py | 1 - packages/smithy-core/tests/unit/test_utils.py | 1 - packages/smithy-http/src/smithy_http/aio/restjson.py | 10 ++++++---- packages/smithy-http/tests/integration/aio/conftest.py | 1 - .../smithy-http/tests/integration/aio/test_aiohttp.py | 1 - packages/smithy-http/tests/integration/aio/test_crt.py | 1 - .../smithy-http/tests/unit/aio/auth/test_apikey.py | 1 - packages/smithy-http/tests/unit/aio/test_endpoints.py | 1 - packages/smithy-http/tests/unit/aio/test_http.py | 1 - packages/smithy-http/tests/unit/aio/test_restjson.py | 1 - packages/smithy-http/tests/unit/test_fields.py | 1 - packages/smithy-http/tests/unit/test_utils.py | 1 - packages/smithy-json/tests/unit/__init__.py | 1 - packages/smithy-json/tests/unit/test_deserializers.py | 1 - packages/smithy-json/tests/unit/test_serializers.py | 1 - pyproject.toml | 4 ++-- 27 files changed, 15 insertions(+), 38 deletions(-) diff --git a/packages/aws-event-stream/tests/unit/_private/__init__.py b/packages/aws-event-stream/tests/unit/_private/__init__.py index 6eb258f2a..7d9702c48 100644 --- a/packages/aws-event-stream/tests/unit/_private/__init__.py +++ b/packages/aws-event-stream/tests/unit/_private/__init__.py @@ -4,6 +4,7 @@ from dataclasses import dataclass from typing import Any, ClassVar, Literal, Self +from aws_event_stream.events import Byte, EventMessage, Long, Short from smithy_core.deserializers import ShapeDeserializer from smithy_core.exceptions import SmithyException from smithy_core.prelude import ( @@ -21,8 +22,6 @@ from smithy_core.shapes import ShapeID, ShapeType from smithy_core.traits import Trait -from aws_event_stream.events import Byte, EventMessage, Long, Short - EVENT_HEADER_TRAIT = Trait(id=ShapeID("smithy.api#eventHeader")) EVENT_PAYLOAD_TRAIT = Trait(id=ShapeID("smithy.api#eventPayload")) ERROR_TRAIT = Trait(id=ShapeID("smithy.api#error"), value="client") diff --git a/packages/aws-event-stream/tests/unit/_private/test_deserializers.py b/packages/aws-event-stream/tests/unit/_private/test_deserializers.py index a153864e9..833e906c8 100644 --- a/packages/aws-event-stream/tests/unit/_private/test_deserializers.py +++ b/packages/aws-event-stream/tests/unit/_private/test_deserializers.py @@ -4,16 +4,15 @@ from typing import Any import pytest -from smithy_core.aio.types import AsyncBytesReader -from smithy_core.deserializers import DeserializeableShape -from smithy_json import JSONCodec - from aws_event_stream._private.deserializers import ( AWSAsyncEventReceiver, EventDeserializer, ) from aws_event_stream.events import Event, EventMessage from aws_event_stream.exceptions import UnmodeledEventError +from smithy_core.aio.types import AsyncBytesReader +from smithy_core.deserializers import DeserializeableShape +from smithy_json import JSONCodec from . import ( EVENT_STREAM_SERDE_CASES, diff --git a/packages/aws-event-stream/tests/unit/_private/test_serializers.py b/packages/aws-event-stream/tests/unit/_private/test_serializers.py index c3f16277e..f96836eef 100644 --- a/packages/aws-event-stream/tests/unit/_private/test_serializers.py +++ b/packages/aws-event-stream/tests/unit/_private/test_serializers.py @@ -1,11 +1,10 @@ # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 import pytest -from smithy_core.serializers import SerializeableShape -from smithy_json import JSONCodec - from aws_event_stream._private.serializers import EventSerializer from aws_event_stream.events import EventMessage +from smithy_core.serializers import SerializeableShape +from smithy_json import JSONCodec from . import EVENT_STREAM_SERDE_CASES, INITIAL_REQUEST_CASE, INITIAL_RESPONSE_CASE diff --git a/packages/aws-event-stream/tests/unit/test_events.py b/packages/aws-event-stream/tests/unit/test_events.py index 5223676a7..aefa0bb65 100644 --- a/packages/aws-event-stream/tests/unit/test_events.py +++ b/packages/aws-event-stream/tests/unit/test_events.py @@ -6,8 +6,6 @@ from io import BytesIO import pytest -from smithy_core.aio.types import AsyncBytesReader - from aws_event_stream.events import ( MAX_HEADER_VALUE_BYTE_LENGTH, MAX_HEADERS_LENGTH, @@ -31,6 +29,7 @@ InvalidIntegerValue, InvalidPayloadLength, ) +from smithy_core.aio.types import AsyncBytesReader EMPTY_MESSAGE = ( ( diff --git a/packages/smithy-core/tests/unit/aio/test_types.py b/packages/smithy-core/tests/unit/aio/test_types.py index b62f3a4b3..ab738828d 100644 --- a/packages/smithy-core/tests/unit/aio/test_types.py +++ b/packages/smithy-core/tests/unit/aio/test_types.py @@ -5,7 +5,6 @@ from typing import Self import pytest - from smithy_core.aio.types import ( AsyncBytesProvider, AsyncBytesReader, diff --git a/packages/smithy-core/tests/unit/test_documents.py b/packages/smithy-core/tests/unit/test_documents.py index 4f7fd93b0..ce717ac7b 100644 --- a/packages/smithy-core/tests/unit/test_documents.py +++ b/packages/smithy-core/tests/unit/test_documents.py @@ -5,7 +5,6 @@ from typing import Any, Self, cast import pytest - from smithy_core.deserializers import ShapeDeserializer from smithy_core.documents import ( Document, diff --git a/packages/smithy-core/tests/unit/test_identity.py b/packages/smithy-core/tests/unit/test_identity.py index dc0698ecd..020961a4f 100644 --- a/packages/smithy-core/tests/unit/test_identity.py +++ b/packages/smithy-core/tests/unit/test_identity.py @@ -4,7 +4,6 @@ import pytest from freezegun import freeze_time - from smithy_core.identity import Identity diff --git a/packages/smithy-core/tests/unit/test_retries.py b/packages/smithy-core/tests/unit/test_retries.py index 2d68da67a..82b6f7d09 100644 --- a/packages/smithy-core/tests/unit/test_retries.py +++ b/packages/smithy-core/tests/unit/test_retries.py @@ -2,7 +2,6 @@ # SPDX-License-Identifier: Apache-2.0 import pytest - from smithy_core.exceptions import SmithyRetryException from smithy_core.interfaces.retries import RetryErrorInfo, RetryErrorType from smithy_core.retries import ExponentialBackoffJitterType as EBJT diff --git a/packages/smithy-core/tests/unit/test_schemas.py b/packages/smithy-core/tests/unit/test_schemas.py index d06c44f78..258782078 100644 --- a/packages/smithy-core/tests/unit/test_schemas.py +++ b/packages/smithy-core/tests/unit/test_schemas.py @@ -1,7 +1,6 @@ from dataclasses import replace import pytest - from smithy_core.exceptions import ExpectationNotMetException from smithy_core.schemas import Schema from smithy_core.shapes import ShapeID, ShapeType diff --git a/packages/smithy-core/tests/unit/test_shapes.py b/packages/smithy-core/tests/unit/test_shapes.py index 26c00715d..80170f1f9 100644 --- a/packages/smithy-core/tests/unit/test_shapes.py +++ b/packages/smithy-core/tests/unit/test_shapes.py @@ -1,5 +1,4 @@ import pytest - from smithy_core.exceptions import ExpectationNotMetException, SmithyException from smithy_core.shapes import ShapeID diff --git a/packages/smithy-core/tests/unit/test_types.py b/packages/smithy-core/tests/unit/test_types.py index a478aad31..0ff54fb3c 100644 --- a/packages/smithy-core/tests/unit/test_types.py +++ b/packages/smithy-core/tests/unit/test_types.py @@ -5,7 +5,6 @@ from datetime import datetime, timezone import pytest - from smithy_core.exceptions import ExpectationNotMetException from smithy_core.types import JsonBlob, JsonString, TimestampFormat diff --git a/packages/smithy-core/tests/unit/test_uri.py b/packages/smithy-core/tests/unit/test_uri.py index e5bcf457d..96d0434e6 100644 --- a/packages/smithy-core/tests/unit/test_uri.py +++ b/packages/smithy-core/tests/unit/test_uri.py @@ -1,7 +1,6 @@ # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 import pytest - from smithy_core import URI, HostType from smithy_core.exceptions import SmithyException diff --git a/packages/smithy-core/tests/unit/test_utils.py b/packages/smithy-core/tests/unit/test_utils.py index 31d243d6b..6147c8d36 100644 --- a/packages/smithy-core/tests/unit/test_utils.py +++ b/packages/smithy-core/tests/unit/test_utils.py @@ -11,7 +11,6 @@ from unittest.mock import Mock import pytest - from smithy_core.exceptions import ExpectationNotMetException from smithy_core.utils import ( ensure_utc, diff --git a/packages/smithy-http/src/smithy_http/aio/restjson.py b/packages/smithy-http/src/smithy_http/aio/restjson.py index f7396c92e..8ee54c923 100644 --- a/packages/smithy-http/src/smithy_http/aio/restjson.py +++ b/packages/smithy-http/src/smithy_http/aio/restjson.py @@ -5,10 +5,12 @@ from smithy_core.documents import DocumentValue from smithy_core.utils import expect_type -from ..restjson import _REST_JSON_CODE_HEADER # pyright: ignore[reportPrivateUsage] -from ..restjson import _REST_JSON_CODE_KEYS # pyright: ignore[reportPrivateUsage] -from ..restjson import _REST_JSON_MESSAGE_KEYS # pyright: ignore[reportPrivateUsage] -from ..restjson import RestJsonErrorInfo +from ..restjson import ( + _REST_JSON_CODE_HEADER, # pyright: ignore[reportPrivateUsage] + _REST_JSON_CODE_KEYS, # pyright: ignore[reportPrivateUsage] + _REST_JSON_MESSAGE_KEYS, # pyright: ignore[reportPrivateUsage] + RestJsonErrorInfo, +) from .interfaces import HTTPResponse diff --git a/packages/smithy-http/tests/integration/aio/conftest.py b/packages/smithy-http/tests/integration/aio/conftest.py index c0c66b642..efb5065bc 100644 --- a/packages/smithy-http/tests/integration/aio/conftest.py +++ b/packages/smithy-http/tests/integration/aio/conftest.py @@ -4,7 +4,6 @@ import pytest from smithy_core import URI from smithy_core.aio.utils import async_list - from smithy_http import Field, Fields from smithy_http.aio import HTTPRequest diff --git a/packages/smithy-http/tests/integration/aio/test_aiohttp.py b/packages/smithy-http/tests/integration/aio/test_aiohttp.py index 54b45c0c1..404afa100 100644 --- a/packages/smithy-http/tests/integration/aio/test_aiohttp.py +++ b/packages/smithy-http/tests/integration/aio/test_aiohttp.py @@ -1,7 +1,6 @@ # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 import pytest - from smithy_http.aio import HTTPRequest from smithy_http.aio.aiohttp import AIOHTTPClient, AIOHTTPClientConfig diff --git a/packages/smithy-http/tests/integration/aio/test_crt.py b/packages/smithy-http/tests/integration/aio/test_crt.py index caed7c7ac..4395579cf 100644 --- a/packages/smithy-http/tests/integration/aio/test_crt.py +++ b/packages/smithy-http/tests/integration/aio/test_crt.py @@ -1,7 +1,6 @@ # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 import pytest - from smithy_http.aio import HTTPRequest from smithy_http.aio.crt import AWSCRTHTTPClient, AWSCRTHTTPClientConfig diff --git a/packages/smithy-http/tests/unit/aio/auth/test_apikey.py b/packages/smithy-http/tests/unit/aio/auth/test_apikey.py index 6ef39ea18..71280aac2 100644 --- a/packages/smithy-http/tests/unit/aio/auth/test_apikey.py +++ b/packages/smithy-http/tests/unit/aio/auth/test_apikey.py @@ -8,7 +8,6 @@ from smithy_core.aio.interfaces.identity import IdentityResolver from smithy_core.exceptions import SmithyIdentityException from smithy_core.interfaces.identity import IdentityProperties - from smithy_http import Field, Fields from smithy_http.aio import HTTPRequest from smithy_http.aio.auth.apikey import ( diff --git a/packages/smithy-http/tests/unit/aio/test_endpoints.py b/packages/smithy-http/tests/unit/aio/test_endpoints.py index e81ad0901..2a3a2230f 100644 --- a/packages/smithy-http/tests/unit/aio/test_endpoints.py +++ b/packages/smithy-http/tests/unit/aio/test_endpoints.py @@ -1,7 +1,6 @@ # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 from smithy_core import URI - from smithy_http import Fields from smithy_http.aio.endpoints import StaticEndpointResolver from smithy_http.endpoints import StaticEndpointParams diff --git a/packages/smithy-http/tests/unit/aio/test_http.py b/packages/smithy-http/tests/unit/aio/test_http.py index 815814f5e..1bcb6520a 100644 --- a/packages/smithy-http/tests/unit/aio/test_http.py +++ b/packages/smithy-http/tests/unit/aio/test_http.py @@ -2,7 +2,6 @@ # SPDX-License-Identifier: Apache-2.0 from smithy_core import URI from smithy_core.aio.utils import async_list - from smithy_http import Field, Fields from smithy_http.aio import HTTPRequest, HTTPResponse diff --git a/packages/smithy-http/tests/unit/aio/test_restjson.py b/packages/smithy-http/tests/unit/aio/test_restjson.py index 4f10fa467..fe55dd3ec 100644 --- a/packages/smithy-http/tests/unit/aio/test_restjson.py +++ b/packages/smithy-http/tests/unit/aio/test_restjson.py @@ -7,7 +7,6 @@ import pytest from smithy_core.aio.utils import async_list from smithy_core.documents import DocumentValue - from smithy_http import tuples_to_fields from smithy_http.aio import HTTPResponse from smithy_http.aio.restjson import parse_rest_json_error_info diff --git a/packages/smithy-http/tests/unit/test_fields.py b/packages/smithy-http/tests/unit/test_fields.py index a368fe221..884c9d105 100644 --- a/packages/smithy-http/tests/unit/test_fields.py +++ b/packages/smithy-http/tests/unit/test_fields.py @@ -5,7 +5,6 @@ # mypy: allow-incomplete-defs import pytest - from smithy_http import Field, Fields from smithy_http.interfaces import FieldPosition diff --git a/packages/smithy-http/tests/unit/test_utils.py b/packages/smithy-http/tests/unit/test_utils.py index 6322d9a75..e3bb9af82 100644 --- a/packages/smithy-http/tests/unit/test_utils.py +++ b/packages/smithy-http/tests/unit/test_utils.py @@ -2,7 +2,6 @@ # SPDX-License-Identifier: Apache-2.0 import pytest from smithy_core.exceptions import SmithyException - from smithy_http.utils import join_query_params, split_header diff --git a/packages/smithy-json/tests/unit/__init__.py b/packages/smithy-json/tests/unit/__init__.py index d82feb010..8592c7087 100644 --- a/packages/smithy-json/tests/unit/__init__.py +++ b/packages/smithy-json/tests/unit/__init__.py @@ -19,7 +19,6 @@ from smithy_core.serializers import ShapeSerializer from smithy_core.shapes import ShapeID, ShapeType from smithy_core.traits import Trait - from smithy_json._private.traits import JSON_NAME, TIMESTAMP_FORMAT SPARSE_TRAIT = Trait(id=ShapeID("smithy.api#sparse")) diff --git a/packages/smithy-json/tests/unit/test_deserializers.py b/packages/smithy-json/tests/unit/test_deserializers.py index 264bc04c6..cee2fcd27 100644 --- a/packages/smithy-json/tests/unit/test_deserializers.py +++ b/packages/smithy-json/tests/unit/test_deserializers.py @@ -14,7 +14,6 @@ STRING, TIMESTAMP, ) - from smithy_json import JSONCodec from . import ( diff --git a/packages/smithy-json/tests/unit/test_serializers.py b/packages/smithy-json/tests/unit/test_serializers.py index 82b525f2e..1eb504b4f 100644 --- a/packages/smithy-json/tests/unit/test_serializers.py +++ b/packages/smithy-json/tests/unit/test_serializers.py @@ -14,7 +14,6 @@ STRING, TIMESTAMP, ) - from smithy_json import JSONCodec from . import ( diff --git a/pyproject.toml b/pyproject.toml index 6bdb5f1b1..4fa06324a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -50,8 +50,8 @@ target-version = "py312" # perhaps in the future: N, PYI, TC, TID # probably not, a lot of work: DOC, D, PL, TRY -# TODO: I, T, UP -select = [ "ASYNC", "E1", "E4", "E7", "E9", "F", "FURB", "G", "LOG", "S" ] +# TODO: T, UP +select = [ "ASYNC", "E1", "E4", "E7", "E9", "F", "FURB", "G", "I", "LOG", "S" ] exclude = [ "packages/smithy-core/src/smithy_core/rfc3986.py" ] [tool.ruff.lint.per-file-ignores] From f34b542814465c1485dc8eb9f5f2f502e2b32728 Mon Sep 17 00:00:00 2001 From: Hayden Baker Date: Wed, 26 Feb 2025 08:31:00 -0800 Subject: [PATCH 2/9] Add ruff lint rule - T --- packages/smithy-core/tests/unit/test_retries.py | 2 -- packages/smithy-http/tests/integration/aio/test_crt.py | 2 -- pyproject.toml | 4 ++-- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/packages/smithy-core/tests/unit/test_retries.py b/packages/smithy-core/tests/unit/test_retries.py index 82b6f7d09..cf24b9c74 100644 --- a/packages/smithy-core/tests/unit/test_retries.py +++ b/packages/smithy-core/tests/unit/test_retries.py @@ -52,8 +52,6 @@ def test_exponential_backoff_strategy( for delay_index, delay_expected in enumerate(expected_delays): delay_actual = bos.compute_next_backoff_delay(retry_attempt=delay_index) - delay_expected2 = delay_expected - print(f"{delay_index=} {delay_actual=} {delay_expected2=}") assert delay_actual == pytest.approx(delay_expected) # type: ignore diff --git a/packages/smithy-http/tests/integration/aio/test_crt.py b/packages/smithy-http/tests/integration/aio/test_crt.py index 4395579cf..3617f4577 100644 --- a/packages/smithy-http/tests/integration/aio/test_crt.py +++ b/packages/smithy-http/tests/integration/aio/test_crt.py @@ -11,9 +11,7 @@ async def test_basic_request_local(sample_request: HTTPRequest) -> None: session = AWSCRTHTTPClient(client_config=config) response = await session.send(request=sample_request) assert response.status == 200 - print(f"{response=}") body = await response.consume_body_async() - print(f"{body=}") assert b"aws" in body diff --git a/pyproject.toml b/pyproject.toml index 4fa06324a..6248410c4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -50,8 +50,8 @@ target-version = "py312" # perhaps in the future: N, PYI, TC, TID # probably not, a lot of work: DOC, D, PL, TRY -# TODO: T, UP -select = [ "ASYNC", "E1", "E4", "E7", "E9", "F", "FURB", "G", "I", "LOG", "S" ] +# TODO: UP +select = [ "ASYNC", "E1", "E4", "E7", "E9", "F", "FURB", "G", "I", "LOG", "S", "T" ] exclude = [ "packages/smithy-core/src/smithy_core/rfc3986.py" ] [tool.ruff.lint.per-file-ignores] From 05616bf83ed4027c5102489370eaf1b0273987a4 Mon Sep 17 00:00:00 2001 From: Hayden Baker Date: Wed, 26 Feb 2025 08:33:22 -0800 Subject: [PATCH 3/9] Add ruff lint rule - UP --- .../smithy-core/src/smithy_core/documents.py | 2 +- .../smithy-core/src/smithy_core/identity.py | 4 +-- .../smithy-core/src/smithy_core/schemas.py | 4 +-- packages/smithy-core/src/smithy_core/types.py | 4 +-- packages/smithy-core/src/smithy_core/utils.py | 10 +++--- .../smithy-core/tests/unit/test_identity.py | 12 +++---- packages/smithy-core/tests/unit/test_types.py | 32 +++++++++---------- packages/smithy-core/tests/unit/test_utils.py | 20 ++++++------ .../smithy-http/src/smithy_http/aio/crt.py | 2 +- .../src/smithy_json/_private/documents.py | 2 +- packages/smithy-json/tests/unit/__init__.py | 22 ++++++------- pyproject.toml | 3 +- 12 files changed, 58 insertions(+), 59 deletions(-) diff --git a/packages/smithy-core/src/smithy_core/documents.py b/packages/smithy-core/src/smithy_core/documents.py index 89328a7a7..4f01d6916 100644 --- a/packages/smithy-core/src/smithy_core/documents.py +++ b/packages/smithy-core/src/smithy_core/documents.py @@ -230,7 +230,7 @@ def _wrap_map(self, value: Mapping[str, DocumentValue]) -> dict[str, "Document"] member_schema = self._schema.members["value"] return {k: self._new_document(v, member_schema) for k, v in value.items()} - result: dict[str, "Document"] = {} + result: dict[str, Document] = {} for k, v in value.items(): result[k] = self._new_document(v, self._schema.members[k]) return result diff --git a/packages/smithy-core/src/smithy_core/identity.py b/packages/smithy-core/src/smithy_core/identity.py index bc8c49929..ed570bffd 100644 --- a/packages/smithy-core/src/smithy_core/identity.py +++ b/packages/smithy-core/src/smithy_core/identity.py @@ -1,6 +1,6 @@ # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 -from datetime import datetime, timezone +from datetime import UTC, datetime from .interfaces import identity as identity_interface from .utils import ensure_utc @@ -28,4 +28,4 @@ def is_expired(self) -> bool: """Whether the identity is expired.""" if self.expiration is None: return False - return datetime.now(tz=timezone.utc) >= self.expiration + return datetime.now(tz=UTC) >= self.expiration diff --git a/packages/smithy-core/src/smithy_core/schemas.py b/packages/smithy-core/src/smithy_core/schemas.py index 0e725d129..bed29d227 100644 --- a/packages/smithy-core/src/smithy_core/schemas.py +++ b/packages/smithy-core/src/smithy_core/schemas.py @@ -67,7 +67,7 @@ def __init__( if members: if isinstance(members, list): - m: dict[str, "Schema"] = {} + m: dict[str, Schema] = {} for member in members: m[member.expect_member_name()] = member members = m @@ -140,7 +140,7 @@ def collection( constructor, this is a dict of member names to a simplified dict containing only ``traits`` and a ``target``. Member schemas will be generated from this. """ - struct_members: dict[str, "Schema"] = {} + struct_members: dict[str, Schema] = {} if members: for k in members.keys(): struct_members[k] = cls.member( diff --git a/packages/smithy-core/src/smithy_core/types.py b/packages/smithy-core/src/smithy_core/types.py index fcc0921ef..f59327754 100644 --- a/packages/smithy-core/src/smithy_core/types.py +++ b/packages/smithy-core/src/smithy_core/types.py @@ -5,7 +5,7 @@ from datetime import datetime from email.utils import format_datetime, parsedate_to_datetime from enum import Enum -from typing import Any, TypeAlias +from typing import Any from .exceptions import ExpectationNotMetException from .utils import ( @@ -16,7 +16,7 @@ serialize_rfc3339, ) -Document: TypeAlias = ( +type Document = ( Mapping[str, "Document"] | Sequence["Document"] | str | int | float | bool | None ) diff --git a/packages/smithy-core/src/smithy_core/utils.py b/packages/smithy-core/src/smithy_core/utils.py index 375b68273..f063ad1aa 100644 --- a/packages/smithy-core/src/smithy_core/utils.py +++ b/packages/smithy-core/src/smithy_core/utils.py @@ -1,7 +1,7 @@ # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 import re -from datetime import datetime, timedelta, timezone +from datetime import UTC, datetime, timedelta from decimal import Decimal from math import isinf, isnan from types import UnionType @@ -24,9 +24,9 @@ def ensure_utc(value: datetime) -> datetime: :returns: A UTC timezone-aware equivalent datetime. """ if value.tzinfo is None: - return value.replace(tzinfo=timezone.utc) + return value.replace(tzinfo=UTC) else: - return value.astimezone(timezone.utc) + return value.astimezone(UTC) # Python is way more permissive on value of non-numerical floats than Smithy is, so we @@ -61,9 +61,9 @@ def epoch_seconds_to_datetime(value: int | float) -> datetime: to years from 1970 through 2038." This affects 32-bit systems. """ try: - return datetime.fromtimestamp(value, tz=timezone.utc) + return datetime.fromtimestamp(value, tz=UTC) except OverflowError: - epoch_zero = datetime(1970, 1, 1, 0, 0, 0, tzinfo=timezone.utc) + epoch_zero = datetime(1970, 1, 1, 0, 0, 0, tzinfo=UTC) return epoch_zero + timedelta(seconds=value) diff --git a/packages/smithy-core/tests/unit/test_identity.py b/packages/smithy-core/tests/unit/test_identity.py index 020961a4f..7a61f4df2 100644 --- a/packages/smithy-core/tests/unit/test_identity.py +++ b/packages/smithy-core/tests/unit/test_identity.py @@ -1,6 +1,6 @@ # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 -from datetime import datetime, timedelta, timezone +from datetime import UTC, datetime, timedelta, timezone import pytest from freezegun import freeze_time @@ -13,7 +13,7 @@ None, timezone(timedelta(hours=3)), timezone(timedelta(hours=-3)), - timezone.utc, + UTC, timezone(timedelta(hours=0)), timezone(timedelta(hours=0, minutes=30)), timezone(timedelta(hours=0, minutes=-30)), @@ -23,7 +23,7 @@ def test_expiration_timezone(time_zone: timezone) -> None: expiration = datetime.now(tz=time_zone) identity = Identity(expiration=expiration) assert identity.expiration is not None - assert identity.expiration.tzinfo == timezone.utc + assert identity.expiration.tzinfo == UTC @pytest.mark.parametrize( @@ -31,20 +31,20 @@ def test_expiration_timezone(time_zone: timezone) -> None: [ ( Identity( - expiration=datetime(year=2023, month=1, day=1, tzinfo=timezone.utc), + expiration=datetime(year=2023, month=1, day=1, tzinfo=UTC), ), True, ), (Identity(), False), ( Identity( - expiration=datetime(year=2023, month=1, day=2, tzinfo=timezone.utc), + expiration=datetime(year=2023, month=1, day=2, tzinfo=UTC), ), False, ), ( Identity( - expiration=datetime(year=2022, month=12, day=31, tzinfo=timezone.utc), + expiration=datetime(year=2022, month=12, day=31, tzinfo=UTC), ), True, ), diff --git a/packages/smithy-core/tests/unit/test_types.py b/packages/smithy-core/tests/unit/test_types.py index 0ff54fb3c..4a004b316 100644 --- a/packages/smithy-core/tests/unit/test_types.py +++ b/packages/smithy-core/tests/unit/test_types.py @@ -2,7 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 # pyright: reportPrivateUsage=false -from datetime import datetime, timezone +from datetime import UTC, datetime import pytest from smithy_core.exceptions import ExpectationNotMetException @@ -67,57 +67,57 @@ def test_blob_from_json_immediately_caches() -> None: ( TimestampFormat.DATE_TIME, "2017-01-01T00:00:00Z", - datetime(2017, 1, 1, tzinfo=timezone.utc), + datetime(2017, 1, 1, tzinfo=UTC), ), ( TimestampFormat.EPOCH_SECONDS, 1483228800, - datetime(2017, 1, 1, tzinfo=timezone.utc), + datetime(2017, 1, 1, tzinfo=UTC), ), ( TimestampFormat.HTTP_DATE, "Sun, 01 Jan 2017 00:00:00 GMT", - datetime(2017, 1, 1, tzinfo=timezone.utc), + datetime(2017, 1, 1, tzinfo=UTC), ), ( TimestampFormat.DATE_TIME, "2017-01-01T00:00:00.000001Z", - datetime(2017, 1, 1, microsecond=1, tzinfo=timezone.utc), + datetime(2017, 1, 1, microsecond=1, tzinfo=UTC), ), ( TimestampFormat.EPOCH_SECONDS, 1483228800.000001, - datetime(2017, 1, 1, microsecond=1, tzinfo=timezone.utc), + datetime(2017, 1, 1, microsecond=1, tzinfo=UTC), ), ( TimestampFormat.DATE_TIME, "1969-12-31T23:59:59Z", - datetime(1969, 12, 31, 23, 59, 59, tzinfo=timezone.utc), + datetime(1969, 12, 31, 23, 59, 59, tzinfo=UTC), ), ( TimestampFormat.EPOCH_SECONDS, -1, - datetime(1969, 12, 31, 23, 59, 59, tzinfo=timezone.utc), + datetime(1969, 12, 31, 23, 59, 59, tzinfo=UTC), ), ( TimestampFormat.HTTP_DATE, "Wed, 31 Dec 1969 23:59:59 GMT", - datetime(1969, 12, 31, 23, 59, 59, tzinfo=timezone.utc), + datetime(1969, 12, 31, 23, 59, 59, tzinfo=UTC), ), ( TimestampFormat.DATE_TIME, "2038-01-19T03:14:08Z", - datetime(2038, 1, 19, 3, 14, 8, tzinfo=timezone.utc), + datetime(2038, 1, 19, 3, 14, 8, tzinfo=UTC), ), ( TimestampFormat.EPOCH_SECONDS, 2147483648, - datetime(2038, 1, 19, 3, 14, 8, tzinfo=timezone.utc), + datetime(2038, 1, 19, 3, 14, 8, tzinfo=UTC), ), ( TimestampFormat.HTTP_DATE, "Tue, 19 Jan 2038 03:14:08 GMT", - datetime(2038, 1, 19, 3, 14, 8, tzinfo=timezone.utc), + datetime(2038, 1, 19, 3, 14, 8, tzinfo=UTC), ), ] @@ -127,22 +127,22 @@ def test_blob_from_json_immediately_caches() -> None: ( TimestampFormat.EPOCH_SECONDS, "1483228800", - datetime(2017, 1, 1, tzinfo=timezone.utc), + datetime(2017, 1, 1, tzinfo=UTC), ), ( TimestampFormat.EPOCH_SECONDS, "1483228800.000001", - datetime(2017, 1, 1, microsecond=1, tzinfo=timezone.utc), + datetime(2017, 1, 1, microsecond=1, tzinfo=UTC), ), ( TimestampFormat.EPOCH_SECONDS, "-1", - datetime(1969, 12, 31, 23, 59, 59, tzinfo=timezone.utc), + datetime(1969, 12, 31, 23, 59, 59, tzinfo=UTC), ), ( TimestampFormat.EPOCH_SECONDS, "2147483648", - datetime(2038, 1, 19, 3, 14, 8, tzinfo=timezone.utc), + datetime(2038, 1, 19, 3, 14, 8, tzinfo=UTC), ), ] TIMESTAMP_FORMAT_DESERIALIZATION_CASES.extend(TIMESTAMP_FORMAT_SERIALIZATION_CASES) diff --git a/packages/smithy-core/tests/unit/test_utils.py b/packages/smithy-core/tests/unit/test_utils.py index 6147c8d36..208ffb3b9 100644 --- a/packages/smithy-core/tests/unit/test_utils.py +++ b/packages/smithy-core/tests/unit/test_utils.py @@ -4,7 +4,7 @@ # mypy: allow-untyped-defs # mypy: allow-incomplete-defs -from datetime import datetime, timedelta, timezone +from datetime import UTC, datetime, timedelta, timezone from decimal import Decimal from math import isnan from typing import Any, NamedTuple @@ -30,14 +30,14 @@ @pytest.mark.parametrize( "given, expected", [ - (datetime(2017, 1, 1), datetime(2017, 1, 1, tzinfo=timezone.utc)), + (datetime(2017, 1, 1), datetime(2017, 1, 1, tzinfo=UTC)), ( - datetime(2017, 1, 1, tzinfo=timezone.utc), - datetime(2017, 1, 1, tzinfo=timezone.utc), + datetime(2017, 1, 1, tzinfo=UTC), + datetime(2017, 1, 1, tzinfo=UTC), ), ( datetime(2017, 1, 1, tzinfo=timezone(timedelta(hours=1))), - datetime(2016, 12, 31, 23, tzinfo=timezone.utc), + datetime(2016, 12, 31, 23, tzinfo=UTC), ), ], ) @@ -199,19 +199,19 @@ class DateTimeTestcase(NamedTuple): DATETIME_TEST_CASES: list[DateTimeTestcase] = [ DateTimeTestcase( - dt_object=datetime(2017, 1, 1, tzinfo=timezone.utc), + dt_object=datetime(2017, 1, 1, tzinfo=UTC), rfc3339_str="2017-01-01T00:00:00Z", epoch_seconds_num=1483228800, epoch_seconds_str="1483228800", ), DateTimeTestcase( - dt_object=datetime(2017, 1, 1, microsecond=1, tzinfo=timezone.utc), + dt_object=datetime(2017, 1, 1, microsecond=1, tzinfo=UTC), rfc3339_str="2017-01-01T00:00:00.000001Z", epoch_seconds_num=1483228800.000001, epoch_seconds_str="1483228800.000001", ), DateTimeTestcase( - dt_object=datetime(1969, 12, 31, 23, 59, 59, tzinfo=timezone.utc), + dt_object=datetime(1969, 12, 31, 23, 59, 59, tzinfo=UTC), rfc3339_str="1969-12-31T23:59:59Z", epoch_seconds_num=-1, epoch_seconds_str="-1", @@ -219,7 +219,7 @@ class DateTimeTestcase(NamedTuple): # The first second affected by the Year 2038 problem where fromtimestamp raises an # OverflowError on 32-bit systems for dates beyond 2038-01-19 03:14:07 UTC. DateTimeTestcase( - dt_object=datetime(2038, 1, 19, 3, 14, 8, tzinfo=timezone.utc), + dt_object=datetime(2038, 1, 19, 3, 14, 8, tzinfo=UTC), rfc3339_str="2038-01-19T03:14:08Z", epoch_seconds_num=2147483648, epoch_seconds_str="2147483648", @@ -269,7 +269,7 @@ def test_epoch_seconds_to_datetime_with_overflow_error(monkeypatch): # type: ig datetime_mock = Mock(wraps=datetime) datetime_mock.fromtimestamp = Mock(side_effect=OverflowError()) monkeypatch.setattr("smithy_core.utils.datetime", datetime_mock) # type: ignore - dt_object = datetime(2038, 1, 19, 3, 14, 8, tzinfo=timezone.utc) + dt_object = datetime(2038, 1, 19, 3, 14, 8, tzinfo=UTC) assert epoch_seconds_to_datetime(2147483648) == dt_object diff --git a/packages/smithy-http/src/smithy_http/aio/crt.py b/packages/smithy-http/src/smithy_http/aio/crt.py index 6cb635a44..51dc048d1 100644 --- a/packages/smithy-http/src/smithy_http/aio/crt.py +++ b/packages/smithy-http/src/smithy_http/aio/crt.py @@ -57,7 +57,7 @@ def _initialize_default_loop(self) -> "crt_io.ClientBootstrap": class AWSCRTHTTPResponse(http_aio_interfaces.HTTPResponse): def __init__(self) -> None: _assert_crt() - self._stream: "crt_http.HttpClientStream | None" = None + self._stream: crt_http.HttpClientStream | None = None self._status_code_future: Future[int] = Future() self._headers_future: Future[Fields] = Future() self._chunk_futures: list[Future[bytes]] = [] diff --git a/packages/smithy-json/src/smithy_json/_private/documents.py b/packages/smithy-json/src/smithy_json/_private/documents.py index 2fb0b66a2..30d92f88c 100644 --- a/packages/smithy-json/src/smithy_json/_private/documents.py +++ b/packages/smithy-json/src/smithy_json/_private/documents.py @@ -121,7 +121,7 @@ def _wrap_map(self, value: Mapping[str, DocumentValue]) -> dict[str, "Document"] if self._schema.shape_type not in (ShapeType.STRUCTURE, ShapeType.UNION): return super()._wrap_map(value) - result: dict[str, "Document"] = {} + result: dict[str, Document] = {} for k, v in value.items(): member_name = self._json_names.get(k, k) result[member_name] = self._new_document( diff --git a/packages/smithy-json/tests/unit/__init__.py b/packages/smithy-json/tests/unit/__init__.py index 8592c7087..40a31a27b 100644 --- a/packages/smithy-json/tests/unit/__init__.py +++ b/packages/smithy-json/tests/unit/__init__.py @@ -1,5 +1,5 @@ from dataclasses import dataclass -from datetime import datetime, timezone +from datetime import UTC, datetime from decimal import Decimal from typing import Any, Self @@ -313,7 +313,7 @@ def _read_optional_map(k: str, d: ShapeDeserializer): (Decimal("1.1"), b"1.1"), (b"foo", b'"Zm9v"'), ("foo", b'"foo"'), - (datetime(2024, 5, 15, tzinfo=timezone.utc), b'"2024-05-15T00:00:00Z"'), + (datetime(2024, 5, 15, tzinfo=UTC), b'"2024-05-15T00:00:00Z"'), (None, b"null"), (["foo"], b'["foo"]'), ({"foo": "bar"}, b'{"foo":"bar"}'), @@ -327,19 +327,19 @@ def _read_optional_map(k: str, d: ShapeDeserializer): (SerdeShape(string_member="foo"), b'{"stringMember":"foo"}'), (SerdeShape(json_name_member="foo"), b'{"jsonName":"foo"}'), ( - SerdeShape(timestamp_member=datetime(2024, 5, 15, tzinfo=timezone.utc)), + SerdeShape(timestamp_member=datetime(2024, 5, 15, tzinfo=UTC)), b'{"timestampMember":"2024-05-15T00:00:00Z"}', ), ( - SerdeShape(date_time_member=datetime(2024, 5, 15, tzinfo=timezone.utc)), + SerdeShape(date_time_member=datetime(2024, 5, 15, tzinfo=UTC)), b'{"dateTimeMember":"2024-05-15T00:00:00Z"}', ), ( - SerdeShape(http_date_member=datetime(2024, 5, 15, tzinfo=timezone.utc)), + SerdeShape(http_date_member=datetime(2024, 5, 15, tzinfo=UTC)), b'{"httpDateMember":"Wed, 15 May 2024 00:00:00 GMT"}', ), ( - SerdeShape(epoch_seconds_member=datetime(2024, 5, 15, tzinfo=timezone.utc)), + SerdeShape(epoch_seconds_member=datetime(2024, 5, 15, tzinfo=UTC)), b'{"epochSecondsMember":1715731200}', ), (SerdeShape(document_member=Document(None)), b'{"documentMember":null}'), @@ -368,26 +368,26 @@ def _read_optional_map(k: str, d: ShapeDeserializer): (Document("foo", schema=STRING), b'"foo"'), (Document("foo", schema=DOCUMENT), b'"foo"'), ( - Document(datetime(2024, 5, 15, tzinfo=timezone.utc), schema=TIMESTAMP), + Document(datetime(2024, 5, 15, tzinfo=UTC), schema=TIMESTAMP), b'"2024-05-15T00:00:00Z"', ), ( Document( - datetime(2024, 5, 15, tzinfo=timezone.utc), + datetime(2024, 5, 15, tzinfo=UTC), schema=SCHEMA.members["dateTimeMember"], ), b'"2024-05-15T00:00:00Z"', ), ( Document( - datetime(2024, 5, 15, tzinfo=timezone.utc), + datetime(2024, 5, 15, tzinfo=UTC), schema=SCHEMA.members["httpDateMember"], ), b'"Wed, 15 May 2024 00:00:00 GMT"', ), ( Document( - datetime(2024, 5, 15, tzinfo=timezone.utc), + datetime(2024, 5, 15, tzinfo=UTC), schema=SCHEMA.members["epochSecondsMember"], ), b"1715731200", @@ -408,7 +408,7 @@ def _read_optional_map(k: str, d: ShapeDeserializer): (Document(1.1, schema=DOCUMENT), b"1.1"), (Document(b"foo", schema=DOCUMENT), b'"Zm9v"'), ( - Document(datetime(2024, 5, 15, tzinfo=timezone.utc), schema=DOCUMENT), + Document(datetime(2024, 5, 15, tzinfo=UTC), schema=DOCUMENT), b'"2024-05-15T00:00:00Z"', ), ] diff --git a/pyproject.toml b/pyproject.toml index 6248410c4..a55b619c1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -50,8 +50,7 @@ target-version = "py312" # perhaps in the future: N, PYI, TC, TID # probably not, a lot of work: DOC, D, PL, TRY -# TODO: UP -select = [ "ASYNC", "E1", "E4", "E7", "E9", "F", "FURB", "G", "I", "LOG", "S", "T" ] +select = [ "ASYNC", "E1", "E4", "E7", "E9", "F", "FURB", "G", "I", "LOG", "S", "T", "UP" ] exclude = [ "packages/smithy-core/src/smithy_core/rfc3986.py" ] [tool.ruff.lint.per-file-ignores] From 3f098bdc918cac92e317937157ef29efe7ea0de6 Mon Sep 17 00:00:00 2001 From: Hayden Baker Date: Wed, 26 Feb 2025 08:39:38 -0800 Subject: [PATCH 4/9] Add ruff lint rule - C4 --- packages/smithy-http/src/smithy_http/__init__.py | 4 ++-- pyproject.toml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/smithy-http/src/smithy_http/__init__.py b/packages/smithy-http/src/smithy_http/__init__.py index 90869db71..fb01c6d12 100644 --- a/packages/smithy-http/src/smithy_http/__init__.py +++ b/packages/smithy-http/src/smithy_http/__init__.py @@ -25,7 +25,7 @@ def __init__( kind: FieldPosition = FieldPosition.HEADER, ): self.name = name - self.values: list[str] = [val for val in values] if values is not None else [] + self.values: list[str] = list(values) if values is not None else [] self.kind = kind def add(self, value: str) -> None: @@ -99,7 +99,7 @@ def __init__( :param encoding: The string encoding to be used when converting the ``Field`` name and value from ``str`` to ``bytes`` for transmission. """ - init_fields = [fld for fld in initial] if initial is not None else [] + init_fields = list(initial) if initial is not None else [] init_field_names = [self._normalize_field_name(fld.name) for fld in init_fields] fname_counter = Counter(init_field_names) repeated_names_exist = ( diff --git a/pyproject.toml b/pyproject.toml index a55b619c1..67cfcd984 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -46,11 +46,11 @@ black = true target-version = "py312" [tool.ruff.lint] -# candidates: C4, DTZ, EM, INP, ISC, PERF, PIE, RUF, SIM118, SIM401, SLOT +# candidates: DTZ, EM, INP, ISC, PERF, PIE, RUF, SIM118, SIM401, SLOT # perhaps in the future: N, PYI, TC, TID # probably not, a lot of work: DOC, D, PL, TRY -select = [ "ASYNC", "E1", "E4", "E7", "E9", "F", "FURB", "G", "I", "LOG", "S", "T", "UP" ] +select = [ "ASYNC", "C4", "E1", "E4", "E7", "E9", "F", "FURB", "G", "I", "LOG", "S", "T", "UP" ] exclude = [ "packages/smithy-core/src/smithy_core/rfc3986.py" ] [tool.ruff.lint.per-file-ignores] From 62840cdbc9dc8c8f2de4a1938bc2dc50bd42ec23 Mon Sep 17 00:00:00 2001 From: Hayden Baker Date: Wed, 26 Feb 2025 09:04:54 -0800 Subject: [PATCH 5/9] Add ruff lint rule - PIE --- packages/smithy-core/src/smithy_core/interceptors.py | 12 ------------ .../src/smithy_core/interfaces/identity.py | 1 - packages/smithy-core/src/smithy_core/retries.py | 1 - .../src/smithy_http/aio/interfaces/auth.py | 1 - pyproject.toml | 4 ++-- 5 files changed, 2 insertions(+), 17 deletions(-) diff --git a/packages/smithy-core/src/smithy_core/interceptors.py b/packages/smithy-core/src/smithy_core/interceptors.py index 0b64d4e90..7b358736d 100644 --- a/packages/smithy-core/src/smithy_core/interceptors.py +++ b/packages/smithy-core/src/smithy_core/interceptors.py @@ -148,7 +148,6 @@ def read_before_execution( the `response`. If multiple `read_before_execution` methods throw exceptions, the latest will be used and earlier ones will be logged and dropped. """ - pass def modify_before_serialization( self, context: InterceptorContext[Request, None, None, None] @@ -193,7 +192,6 @@ def read_before_serialization( If exceptions are thrown by this hook, execution will jump to `modify_before_completion` with the thrown exception as the `response`. """ - pass def read_after_serialization( self, context: InterceptorContext[Request, None, TransportRequest, None] @@ -214,7 +212,6 @@ def read_after_serialization( If exceptions are thrown by this hook, execution will jump to `modify_before_completion` with the thrown exception as the `response`. """ - pass def modify_before_retry_loop( self, context: InterceptorContext[Request, None, TransportRequest, None] @@ -259,7 +256,6 @@ def read_before_attempt( exception as the `response` If multiple `read_before_attempt` methods throw exceptions, the latest will be used and earlier ones will be logged and dropped. """ - pass def modify_before_signing( self, context: InterceptorContext[Request, None, TransportRequest, None] @@ -309,7 +305,6 @@ def read_before_signing( If exceptions are thrown by this hook, execution will jump to `modify_before_attempt_completion` with the thrown exception as the `response`. """ - pass def read_after_signing( self, context: InterceptorContext[Request, None, TransportRequest, None] @@ -333,7 +328,6 @@ def read_after_signing( If exceptions are thrown by this hook, execution will jump to `modify_before_attempt_completion` with the thrown exception as the `response`. """ - pass def modify_before_transmit( self, context: InterceptorContext[Request, None, TransportRequest, None] @@ -384,7 +378,6 @@ def read_before_transmit( If exceptions are thrown by this hook, execution will jump to `modify_before_attempt_completion` with the thrown exception as the `response`. """ - pass def read_after_transmit( self, @@ -411,7 +404,6 @@ def read_after_transmit( If exceptions are thrown by this hook, execution will jump to `modify_before_attempt_completion` with the thrown exception as the `response`. """ - pass def modify_before_deserialization( self, @@ -467,7 +459,6 @@ def read_before_deserialization( If exceptions are thrown by this hook, execution will jump to `modify_before_attempt_completion` with the thrown exception as the `response`. """ - pass def read_after_deserialization( self, @@ -495,7 +486,6 @@ def read_after_deserialization( If exceptions are thrown by this hook, execution will jump to `modify_before_attempt_completion` with the thrown exception as the `response`. """ - pass def modify_before_attempt_completion( self, @@ -554,7 +544,6 @@ def read_after_attempt( execution will then jump to `read_before_attempt`. Otherwise, execution will jump to `modify_before_completion` with the thrown exception as the `response`. """ - pass def modify_before_completion( self, @@ -605,4 +594,3 @@ def read_after_execution( final response. If multiple `read_after_execution` methods throw exceptions, the latest will be used and earlier ones will be logged and dropped. """ - pass diff --git a/packages/smithy-core/src/smithy_core/interfaces/identity.py b/packages/smithy-core/src/smithy_core/interfaces/identity.py index 095314637..b96ae9bc9 100644 --- a/packages/smithy-core/src/smithy_core/interfaces/identity.py +++ b/packages/smithy-core/src/smithy_core/interfaces/identity.py @@ -25,7 +25,6 @@ def is_expired(self) -> bool: class IdentityProperties(TypedDict): """Properties used to help determine the identity to return.""" - ... IdentityPropertiesType = TypeVar("IdentityPropertiesType", bound=IdentityProperties) diff --git a/packages/smithy-core/src/smithy_core/retries.py b/packages/smithy-core/src/smithy_core/retries.py index e9c75913f..07b051da9 100644 --- a/packages/smithy-core/src/smithy_core/retries.py +++ b/packages/smithy-core/src/smithy_core/retries.py @@ -242,4 +242,3 @@ def refresh_retry_token_for_retry( def record_success(self, *, token: retries_interface.RetryToken) -> None: """Not used by this retry strategy.""" - pass diff --git a/packages/smithy-http/src/smithy_http/aio/interfaces/auth.py b/packages/smithy-http/src/smithy_http/aio/interfaces/auth.py index 8c1e52624..62e3dffd9 100644 --- a/packages/smithy-http/src/smithy_http/aio/interfaces/auth.py +++ b/packages/smithy-http/src/smithy_http/aio/interfaces/auth.py @@ -23,7 +23,6 @@ class SigningProperties(TypedDict): """Additional properties loaded to modify the signing process.""" - ... SigningPropertiesType = TypeVar("SigningPropertiesType", bound=SigningProperties) diff --git a/pyproject.toml b/pyproject.toml index 67cfcd984..f6bc46fd2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -46,11 +46,11 @@ black = true target-version = "py312" [tool.ruff.lint] -# candidates: DTZ, EM, INP, ISC, PERF, PIE, RUF, SIM118, SIM401, SLOT +# candidates: DTZ, EM, INP, ISC, PERF, RUF, SIM118, SIM401, SLOT # perhaps in the future: N, PYI, TC, TID # probably not, a lot of work: DOC, D, PL, TRY -select = [ "ASYNC", "C4", "E1", "E4", "E7", "E9", "F", "FURB", "G", "I", "LOG", "S", "T", "UP" ] +select = [ "ASYNC", "C4", "E1", "E4", "E7", "E9", "F", "FURB", "G", "I", "LOG", "PIE", "S", "T", "UP" ] exclude = [ "packages/smithy-core/src/smithy_core/rfc3986.py" ] [tool.ruff.lint.per-file-ignores] From cd95ce15fd9cc7fe8aca8fc74b30de84c78653ae Mon Sep 17 00:00:00 2001 From: Hayden Baker Date: Wed, 26 Feb 2025 09:09:27 -0800 Subject: [PATCH 6/9] Add ruff lint rule - RUF --- packages/aws-event-stream/src/aws_event_stream/events.py | 9 +++++---- packages/smithy-core/src/smithy_core/schemas.py | 4 ++-- packages/smithy-http/src/smithy_http/aio/aiohttp.py | 2 +- packages/smithy-http/src/smithy_http/aio/auth/apikey.py | 2 +- packages/smithy-http/src/smithy_http/aio/crt.py | 4 ++-- pyproject.toml | 4 ++-- 6 files changed, 13 insertions(+), 12 deletions(-) diff --git a/packages/aws-event-stream/src/aws_event_stream/events.py b/packages/aws-event-stream/src/aws_event_stream/events.py index cdd76d493..208f4ac3a 100644 --- a/packages/aws-event-stream/src/aws_event_stream/events.py +++ b/packages/aws-event-stream/src/aws_event_stream/events.py @@ -15,6 +15,7 @@ from dataclasses import dataclass from io import BytesIO from struct import pack, unpack +from types import MappingProxyType from typing import Literal, Self from smithy_core.aio.interfaces import AsyncByteStream @@ -610,11 +611,11 @@ class _DecodeUtils: INT64_BYTE_FORMAT = "!q" # uint byte size to unpack format - UINT_BYTE_FORMAT: dict[_ArraySize, str] = { + UINT_BYTE_FORMAT: Mapping[_ArraySize, str] = MappingProxyType({ 1: UINT8_BYTE_FORMAT, 2: UINT16_BYTE_FORMAT, 4: UINT32_BYTE_FORMAT, - } + }) @staticmethod def unpack_uint8(data: BytesLike) -> tuple[int, int]: @@ -749,7 +750,7 @@ class EventHeaderDecoder(Iterator[tuple[str, HEADER_VALUE]]): # Maps header type to appropriate unpacking function # These unpacking functions return the value and the amount unpacked - _HEADER_TYPE_MAP: dict[int, Callable[[BytesLike], tuple[HEADER_VALUE, int]]] = { + _HEADER_TYPE_MAP: Mapping[int, Callable[[BytesLike], tuple[HEADER_VALUE, int]]] = MappingProxyType({ # Boolean headers have no data bytes following the type signifier, so they # can just return static values. 0: lambda b: (True, 0), # boolean_true @@ -762,7 +763,7 @@ class EventHeaderDecoder(Iterator[tuple[str, HEADER_VALUE]]): 7: _DecodeUtils.unpack_utf8_string, # string 8: _DecodeUtils.unpack_timestamp, # timestamp 9: _DecodeUtils.unpack_uuid, # uuid - } + }) def __init__(self, header_bytes: BytesLike) -> None: """Initialize an event header decoder. diff --git a/packages/smithy-core/src/smithy_core/schemas.py b/packages/smithy-core/src/smithy_core/schemas.py index bed29d227..967eb7a78 100644 --- a/packages/smithy-core/src/smithy_core/schemas.py +++ b/packages/smithy-core/src/smithy_core/schemas.py @@ -50,8 +50,8 @@ def __init__( if any(_member_props) and not all(_member_props): raise SmithyException( "If any member property is set, all member properties must be set. " - f"member_name: {repr(id.member)}, member_target: " - f"{repr(member_target)}, member_index: {repr(member_index)}" + f"member_name: {id.member!r}, member_target: " + f"{member_target!r}, member_index: {member_index!r}" ) # setattr is required because the class is frozen diff --git a/packages/smithy-http/src/smithy_http/aio/aiohttp.py b/packages/smithy-http/src/smithy_http/aio/aiohttp.py index 6ac0464a4..04cafaed8 100644 --- a/packages/smithy-http/src/smithy_http/aio/aiohttp.py +++ b/packages/smithy-http/src/smithy_http/aio/aiohttp.py @@ -12,7 +12,7 @@ import aiohttp try: - import aiohttp # noqa: F811 + import aiohttp HAS_AIOHTTP = True except ImportError: diff --git a/packages/smithy-http/src/smithy_http/aio/auth/apikey.py b/packages/smithy-http/src/smithy_http/aio/auth/apikey.py index 084d5e027..c85e7af22 100644 --- a/packages/smithy-http/src/smithy_http/aio/auth/apikey.py +++ b/packages/smithy-http/src/smithy_http/aio/auth/apikey.py @@ -108,7 +108,7 @@ async def sign( ) case ApiKeyLocation.HEADER: value = identity.api_key - if "scheme" in signing_properties and signing_properties["scheme"]: + if signing_properties.get("scheme"): value = f"{signing_properties['scheme']} {value}" http_request.fields.set_field( Field(name=signing_properties["name"], values=[value]) diff --git a/packages/smithy-http/src/smithy_http/aio/crt.py b/packages/smithy-http/src/smithy_http/aio/crt.py index 51dc048d1..2dec88a06 100644 --- a/packages/smithy-http/src/smithy_http/aio/crt.py +++ b/packages/smithy-http/src/smithy_http/aio/crt.py @@ -18,8 +18,8 @@ from awscrt import io as crt_io try: - from awscrt import http as crt_http # noqa: F811 - from awscrt import io as crt_io # noqa: F811 + from awscrt import http as crt_http + from awscrt import io as crt_io HAS_CRT = True except ImportError: diff --git a/pyproject.toml b/pyproject.toml index f6bc46fd2..80da06ae7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -46,11 +46,11 @@ black = true target-version = "py312" [tool.ruff.lint] -# candidates: DTZ, EM, INP, ISC, PERF, RUF, SIM118, SIM401, SLOT +# candidates: DTZ, EM, INP, ISC, PERF, SIM118, SIM401, SLOT # perhaps in the future: N, PYI, TC, TID # probably not, a lot of work: DOC, D, PL, TRY -select = [ "ASYNC", "C4", "E1", "E4", "E7", "E9", "F", "FURB", "G", "I", "LOG", "PIE", "S", "T", "UP" ] +select = [ "ASYNC", "C4", "E1", "E4", "E7", "E9", "F", "FURB", "G", "I", "LOG", "PIE", "RUF", "S", "T", "UP" ] exclude = [ "packages/smithy-core/src/smithy_core/rfc3986.py" ] [tool.ruff.lint.per-file-ignores] From 570a12852d423465e4e2f43688da3356ddf42c5c Mon Sep 17 00:00:00 2001 From: Hayden Baker Date: Wed, 26 Feb 2025 09:22:33 -0800 Subject: [PATCH 7/9] Re-run ruff format --- .../src/aws_event_stream/events.py | 44 +++++++++++-------- .../src/smithy_core/interfaces/identity.py | 1 - .../src/smithy_http/aio/interfaces/auth.py | 1 - 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/packages/aws-event-stream/src/aws_event_stream/events.py b/packages/aws-event-stream/src/aws_event_stream/events.py index 208f4ac3a..8d52bde65 100644 --- a/packages/aws-event-stream/src/aws_event_stream/events.py +++ b/packages/aws-event-stream/src/aws_event_stream/events.py @@ -611,11 +611,13 @@ class _DecodeUtils: INT64_BYTE_FORMAT = "!q" # uint byte size to unpack format - UINT_BYTE_FORMAT: Mapping[_ArraySize, str] = MappingProxyType({ - 1: UINT8_BYTE_FORMAT, - 2: UINT16_BYTE_FORMAT, - 4: UINT32_BYTE_FORMAT, - }) + UINT_BYTE_FORMAT: Mapping[_ArraySize, str] = MappingProxyType( + { + 1: UINT8_BYTE_FORMAT, + 2: UINT16_BYTE_FORMAT, + 4: UINT32_BYTE_FORMAT, + } + ) @staticmethod def unpack_uint8(data: BytesLike) -> tuple[int, int]: @@ -750,20 +752,24 @@ class EventHeaderDecoder(Iterator[tuple[str, HEADER_VALUE]]): # Maps header type to appropriate unpacking function # These unpacking functions return the value and the amount unpacked - _HEADER_TYPE_MAP: Mapping[int, Callable[[BytesLike], tuple[HEADER_VALUE, int]]] = MappingProxyType({ - # Boolean headers have no data bytes following the type signifier, so they - # can just return static values. - 0: lambda b: (True, 0), # boolean_true - 1: lambda b: (False, 0), # boolean_false - 2: _DecodeUtils.unpack_int8, # byte - 3: _DecodeUtils.unpack_int16, # short - 4: _DecodeUtils.unpack_int32, # integer - 5: _DecodeUtils.unpack_int64, # long - 6: _DecodeUtils.unpack_byte_array, # byte_array - 7: _DecodeUtils.unpack_utf8_string, # string - 8: _DecodeUtils.unpack_timestamp, # timestamp - 9: _DecodeUtils.unpack_uuid, # uuid - }) + _HEADER_TYPE_MAP: Mapping[int, Callable[[BytesLike], tuple[HEADER_VALUE, int]]] = ( + MappingProxyType( + { + # Boolean headers have no data bytes following the type signifier, so they + # can just return static values. + 0: lambda b: (True, 0), # boolean_true + 1: lambda b: (False, 0), # boolean_false + 2: _DecodeUtils.unpack_int8, # byte + 3: _DecodeUtils.unpack_int16, # short + 4: _DecodeUtils.unpack_int32, # integer + 5: _DecodeUtils.unpack_int64, # long + 6: _DecodeUtils.unpack_byte_array, # byte_array + 7: _DecodeUtils.unpack_utf8_string, # string + 8: _DecodeUtils.unpack_timestamp, # timestamp + 9: _DecodeUtils.unpack_uuid, # uuid + } + ) + ) def __init__(self, header_bytes: BytesLike) -> None: """Initialize an event header decoder. diff --git a/packages/smithy-core/src/smithy_core/interfaces/identity.py b/packages/smithy-core/src/smithy_core/interfaces/identity.py index b96ae9bc9..765e32c22 100644 --- a/packages/smithy-core/src/smithy_core/interfaces/identity.py +++ b/packages/smithy-core/src/smithy_core/interfaces/identity.py @@ -26,7 +26,6 @@ class IdentityProperties(TypedDict): """Properties used to help determine the identity to return.""" - IdentityPropertiesType = TypeVar("IdentityPropertiesType", bound=IdentityProperties) IdentityPropertiesType_contra = TypeVar( "IdentityPropertiesType_contra", bound=IdentityProperties, contravariant=True diff --git a/packages/smithy-http/src/smithy_http/aio/interfaces/auth.py b/packages/smithy-http/src/smithy_http/aio/interfaces/auth.py index 62e3dffd9..0a40a8dad 100644 --- a/packages/smithy-http/src/smithy_http/aio/interfaces/auth.py +++ b/packages/smithy-http/src/smithy_http/aio/interfaces/auth.py @@ -24,7 +24,6 @@ class SigningProperties(TypedDict): """Additional properties loaded to modify the signing process.""" - SigningPropertiesType = TypeVar("SigningPropertiesType", bound=SigningProperties) SigningPropertiesType_contra = TypeVar( "SigningPropertiesType_contra", bound=SigningProperties, contravariant=True From 1f5b93d5b4944ac4f368bf1898455e0193c86d6d Mon Sep 17 00:00:00 2001 From: Hayden Baker Date: Wed, 26 Feb 2025 09:37:50 -0800 Subject: [PATCH 8/9] Fix typing issue in ApiKeySigner --- packages/smithy-http/src/smithy_http/aio/auth/apikey.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/smithy-http/src/smithy_http/aio/auth/apikey.py b/packages/smithy-http/src/smithy_http/aio/auth/apikey.py index c85e7af22..cacb81b0c 100644 --- a/packages/smithy-http/src/smithy_http/aio/auth/apikey.py +++ b/packages/smithy-http/src/smithy_http/aio/auth/apikey.py @@ -108,8 +108,8 @@ async def sign( ) case ApiKeyLocation.HEADER: value = identity.api_key - if signing_properties.get("scheme"): - value = f"{signing_properties['scheme']} {value}" + if (scheme := signing_properties.get("scheme", None)) is not None: + value = f"{scheme} {value}" http_request.fields.set_field( Field(name=signing_properties["name"], values=[value]) ) From c8c0defe3c1fc19a9f5a3c0623e57e15093d5260 Mon Sep 17 00:00:00 2001 From: Hayden Baker Date: Wed, 26 Feb 2025 10:04:00 -0800 Subject: [PATCH 9/9] Fix import order in tests for sub-projects --- packages/aws-event-stream/pyproject.toml | 3 +++ packages/aws-event-stream/tests/unit/_private/__init__.py | 3 ++- .../tests/unit/_private/test_deserializers.py | 7 ++++--- .../tests/unit/_private/test_serializers.py | 5 +++-- packages/aws-event-stream/tests/unit/test_events.py | 3 ++- packages/smithy-aws-core/pyproject.toml | 3 +++ packages/smithy-core/pyproject.toml | 3 +++ packages/smithy-core/tests/unit/aio/test_types.py | 1 + packages/smithy-core/tests/unit/test_documents.py | 1 + packages/smithy-core/tests/unit/test_identity.py | 1 + packages/smithy-core/tests/unit/test_retries.py | 1 + packages/smithy-core/tests/unit/test_schemas.py | 1 + packages/smithy-core/tests/unit/test_shapes.py | 1 + packages/smithy-core/tests/unit/test_types.py | 1 + packages/smithy-core/tests/unit/test_uri.py | 1 + packages/smithy-core/tests/unit/test_utils.py | 1 + packages/smithy-event-stream/pyproject.toml | 3 +++ packages/smithy-http/pyproject.toml | 3 +++ packages/smithy-http/tests/integration/aio/conftest.py | 1 + packages/smithy-http/tests/integration/aio/test_aiohttp.py | 1 + packages/smithy-http/tests/integration/aio/test_crt.py | 1 + packages/smithy-http/tests/unit/aio/auth/test_apikey.py | 1 + packages/smithy-http/tests/unit/aio/test_endpoints.py | 1 + packages/smithy-http/tests/unit/aio/test_http.py | 1 + packages/smithy-http/tests/unit/aio/test_restjson.py | 1 + packages/smithy-http/tests/unit/test_fields.py | 1 + packages/smithy-http/tests/unit/test_utils.py | 1 + packages/smithy-json/pyproject.toml | 3 +++ packages/smithy-json/tests/unit/__init__.py | 1 + packages/smithy-json/tests/unit/test_deserializers.py | 1 + packages/smithy-json/tests/unit/test_serializers.py | 1 + 31 files changed, 50 insertions(+), 7 deletions(-) diff --git a/packages/aws-event-stream/pyproject.toml b/packages/aws-event-stream/pyproject.toml index 82c4cf1cf..eb7f20268 100644 --- a/packages/aws-event-stream/pyproject.toml +++ b/packages/aws-event-stream/pyproject.toml @@ -17,3 +17,6 @@ build-backend = "hatchling.build" exclude = [ "tests", ] + +[tool.ruff] +src = ["src"] diff --git a/packages/aws-event-stream/tests/unit/_private/__init__.py b/packages/aws-event-stream/tests/unit/_private/__init__.py index 7d9702c48..6eb258f2a 100644 --- a/packages/aws-event-stream/tests/unit/_private/__init__.py +++ b/packages/aws-event-stream/tests/unit/_private/__init__.py @@ -4,7 +4,6 @@ from dataclasses import dataclass from typing import Any, ClassVar, Literal, Self -from aws_event_stream.events import Byte, EventMessage, Long, Short from smithy_core.deserializers import ShapeDeserializer from smithy_core.exceptions import SmithyException from smithy_core.prelude import ( @@ -22,6 +21,8 @@ from smithy_core.shapes import ShapeID, ShapeType from smithy_core.traits import Trait +from aws_event_stream.events import Byte, EventMessage, Long, Short + EVENT_HEADER_TRAIT = Trait(id=ShapeID("smithy.api#eventHeader")) EVENT_PAYLOAD_TRAIT = Trait(id=ShapeID("smithy.api#eventPayload")) ERROR_TRAIT = Trait(id=ShapeID("smithy.api#error"), value="client") diff --git a/packages/aws-event-stream/tests/unit/_private/test_deserializers.py b/packages/aws-event-stream/tests/unit/_private/test_deserializers.py index 833e906c8..a153864e9 100644 --- a/packages/aws-event-stream/tests/unit/_private/test_deserializers.py +++ b/packages/aws-event-stream/tests/unit/_private/test_deserializers.py @@ -4,15 +4,16 @@ from typing import Any import pytest +from smithy_core.aio.types import AsyncBytesReader +from smithy_core.deserializers import DeserializeableShape +from smithy_json import JSONCodec + from aws_event_stream._private.deserializers import ( AWSAsyncEventReceiver, EventDeserializer, ) from aws_event_stream.events import Event, EventMessage from aws_event_stream.exceptions import UnmodeledEventError -from smithy_core.aio.types import AsyncBytesReader -from smithy_core.deserializers import DeserializeableShape -from smithy_json import JSONCodec from . import ( EVENT_STREAM_SERDE_CASES, diff --git a/packages/aws-event-stream/tests/unit/_private/test_serializers.py b/packages/aws-event-stream/tests/unit/_private/test_serializers.py index f96836eef..c3f16277e 100644 --- a/packages/aws-event-stream/tests/unit/_private/test_serializers.py +++ b/packages/aws-event-stream/tests/unit/_private/test_serializers.py @@ -1,11 +1,12 @@ # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 import pytest -from aws_event_stream._private.serializers import EventSerializer -from aws_event_stream.events import EventMessage from smithy_core.serializers import SerializeableShape from smithy_json import JSONCodec +from aws_event_stream._private.serializers import EventSerializer +from aws_event_stream.events import EventMessage + from . import EVENT_STREAM_SERDE_CASES, INITIAL_REQUEST_CASE, INITIAL_RESPONSE_CASE diff --git a/packages/aws-event-stream/tests/unit/test_events.py b/packages/aws-event-stream/tests/unit/test_events.py index aefa0bb65..5223676a7 100644 --- a/packages/aws-event-stream/tests/unit/test_events.py +++ b/packages/aws-event-stream/tests/unit/test_events.py @@ -6,6 +6,8 @@ from io import BytesIO import pytest +from smithy_core.aio.types import AsyncBytesReader + from aws_event_stream.events import ( MAX_HEADER_VALUE_BYTE_LENGTH, MAX_HEADERS_LENGTH, @@ -29,7 +31,6 @@ InvalidIntegerValue, InvalidPayloadLength, ) -from smithy_core.aio.types import AsyncBytesReader EMPTY_MESSAGE = ( ( diff --git a/packages/smithy-aws-core/pyproject.toml b/packages/smithy-aws-core/pyproject.toml index 1d628f474..991c6130b 100644 --- a/packages/smithy-aws-core/pyproject.toml +++ b/packages/smithy-aws-core/pyproject.toml @@ -16,3 +16,6 @@ build-backend = "hatchling.build" exclude = [ "tests", ] + +[tool.ruff] +src = ["src"] diff --git a/packages/smithy-core/pyproject.toml b/packages/smithy-core/pyproject.toml index 91d867d73..81856563c 100644 --- a/packages/smithy-core/pyproject.toml +++ b/packages/smithy-core/pyproject.toml @@ -19,3 +19,6 @@ build-backend = "hatchling.build" exclude = [ "tests", ] + +[tool.ruff] +src = ["src"] diff --git a/packages/smithy-core/tests/unit/aio/test_types.py b/packages/smithy-core/tests/unit/aio/test_types.py index ab738828d..b62f3a4b3 100644 --- a/packages/smithy-core/tests/unit/aio/test_types.py +++ b/packages/smithy-core/tests/unit/aio/test_types.py @@ -5,6 +5,7 @@ from typing import Self import pytest + from smithy_core.aio.types import ( AsyncBytesProvider, AsyncBytesReader, diff --git a/packages/smithy-core/tests/unit/test_documents.py b/packages/smithy-core/tests/unit/test_documents.py index ce717ac7b..4f7fd93b0 100644 --- a/packages/smithy-core/tests/unit/test_documents.py +++ b/packages/smithy-core/tests/unit/test_documents.py @@ -5,6 +5,7 @@ from typing import Any, Self, cast import pytest + from smithy_core.deserializers import ShapeDeserializer from smithy_core.documents import ( Document, diff --git a/packages/smithy-core/tests/unit/test_identity.py b/packages/smithy-core/tests/unit/test_identity.py index 7a61f4df2..350f26d5f 100644 --- a/packages/smithy-core/tests/unit/test_identity.py +++ b/packages/smithy-core/tests/unit/test_identity.py @@ -4,6 +4,7 @@ import pytest from freezegun import freeze_time + from smithy_core.identity import Identity diff --git a/packages/smithy-core/tests/unit/test_retries.py b/packages/smithy-core/tests/unit/test_retries.py index cf24b9c74..e79173f66 100644 --- a/packages/smithy-core/tests/unit/test_retries.py +++ b/packages/smithy-core/tests/unit/test_retries.py @@ -2,6 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 import pytest + from smithy_core.exceptions import SmithyRetryException from smithy_core.interfaces.retries import RetryErrorInfo, RetryErrorType from smithy_core.retries import ExponentialBackoffJitterType as EBJT diff --git a/packages/smithy-core/tests/unit/test_schemas.py b/packages/smithy-core/tests/unit/test_schemas.py index 258782078..d06c44f78 100644 --- a/packages/smithy-core/tests/unit/test_schemas.py +++ b/packages/smithy-core/tests/unit/test_schemas.py @@ -1,6 +1,7 @@ from dataclasses import replace import pytest + from smithy_core.exceptions import ExpectationNotMetException from smithy_core.schemas import Schema from smithy_core.shapes import ShapeID, ShapeType diff --git a/packages/smithy-core/tests/unit/test_shapes.py b/packages/smithy-core/tests/unit/test_shapes.py index 80170f1f9..26c00715d 100644 --- a/packages/smithy-core/tests/unit/test_shapes.py +++ b/packages/smithy-core/tests/unit/test_shapes.py @@ -1,4 +1,5 @@ import pytest + from smithy_core.exceptions import ExpectationNotMetException, SmithyException from smithy_core.shapes import ShapeID diff --git a/packages/smithy-core/tests/unit/test_types.py b/packages/smithy-core/tests/unit/test_types.py index 4a004b316..b7c48b697 100644 --- a/packages/smithy-core/tests/unit/test_types.py +++ b/packages/smithy-core/tests/unit/test_types.py @@ -5,6 +5,7 @@ from datetime import UTC, datetime import pytest + from smithy_core.exceptions import ExpectationNotMetException from smithy_core.types import JsonBlob, JsonString, TimestampFormat diff --git a/packages/smithy-core/tests/unit/test_uri.py b/packages/smithy-core/tests/unit/test_uri.py index 96d0434e6..e5bcf457d 100644 --- a/packages/smithy-core/tests/unit/test_uri.py +++ b/packages/smithy-core/tests/unit/test_uri.py @@ -1,6 +1,7 @@ # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 import pytest + from smithy_core import URI, HostType from smithy_core.exceptions import SmithyException diff --git a/packages/smithy-core/tests/unit/test_utils.py b/packages/smithy-core/tests/unit/test_utils.py index 208ffb3b9..dc1439a8e 100644 --- a/packages/smithy-core/tests/unit/test_utils.py +++ b/packages/smithy-core/tests/unit/test_utils.py @@ -11,6 +11,7 @@ from unittest.mock import Mock import pytest + from smithy_core.exceptions import ExpectationNotMetException from smithy_core.utils import ( ensure_utc, diff --git a/packages/smithy-event-stream/pyproject.toml b/packages/smithy-event-stream/pyproject.toml index b4a0c5f6d..51406eceb 100644 --- a/packages/smithy-event-stream/pyproject.toml +++ b/packages/smithy-event-stream/pyproject.toml @@ -16,3 +16,6 @@ build-backend = "hatchling.build" exclude = [ "tests", ] + +[tool.ruff] +src = ["src"] diff --git a/packages/smithy-http/pyproject.toml b/packages/smithy-http/pyproject.toml index 26400ab3e..0693786e9 100644 --- a/packages/smithy-http/pyproject.toml +++ b/packages/smithy-http/pyproject.toml @@ -24,3 +24,6 @@ build-backend = "hatchling.build" exclude = [ "tests", ] + +[tool.ruff] +src = ["src"] diff --git a/packages/smithy-http/tests/integration/aio/conftest.py b/packages/smithy-http/tests/integration/aio/conftest.py index efb5065bc..c0c66b642 100644 --- a/packages/smithy-http/tests/integration/aio/conftest.py +++ b/packages/smithy-http/tests/integration/aio/conftest.py @@ -4,6 +4,7 @@ import pytest from smithy_core import URI from smithy_core.aio.utils import async_list + from smithy_http import Field, Fields from smithy_http.aio import HTTPRequest diff --git a/packages/smithy-http/tests/integration/aio/test_aiohttp.py b/packages/smithy-http/tests/integration/aio/test_aiohttp.py index 404afa100..54b45c0c1 100644 --- a/packages/smithy-http/tests/integration/aio/test_aiohttp.py +++ b/packages/smithy-http/tests/integration/aio/test_aiohttp.py @@ -1,6 +1,7 @@ # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 import pytest + from smithy_http.aio import HTTPRequest from smithy_http.aio.aiohttp import AIOHTTPClient, AIOHTTPClientConfig diff --git a/packages/smithy-http/tests/integration/aio/test_crt.py b/packages/smithy-http/tests/integration/aio/test_crt.py index 3617f4577..54072546a 100644 --- a/packages/smithy-http/tests/integration/aio/test_crt.py +++ b/packages/smithy-http/tests/integration/aio/test_crt.py @@ -1,6 +1,7 @@ # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 import pytest + from smithy_http.aio import HTTPRequest from smithy_http.aio.crt import AWSCRTHTTPClient, AWSCRTHTTPClientConfig diff --git a/packages/smithy-http/tests/unit/aio/auth/test_apikey.py b/packages/smithy-http/tests/unit/aio/auth/test_apikey.py index 71280aac2..6ef39ea18 100644 --- a/packages/smithy-http/tests/unit/aio/auth/test_apikey.py +++ b/packages/smithy-http/tests/unit/aio/auth/test_apikey.py @@ -8,6 +8,7 @@ from smithy_core.aio.interfaces.identity import IdentityResolver from smithy_core.exceptions import SmithyIdentityException from smithy_core.interfaces.identity import IdentityProperties + from smithy_http import Field, Fields from smithy_http.aio import HTTPRequest from smithy_http.aio.auth.apikey import ( diff --git a/packages/smithy-http/tests/unit/aio/test_endpoints.py b/packages/smithy-http/tests/unit/aio/test_endpoints.py index 2a3a2230f..e81ad0901 100644 --- a/packages/smithy-http/tests/unit/aio/test_endpoints.py +++ b/packages/smithy-http/tests/unit/aio/test_endpoints.py @@ -1,6 +1,7 @@ # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 from smithy_core import URI + from smithy_http import Fields from smithy_http.aio.endpoints import StaticEndpointResolver from smithy_http.endpoints import StaticEndpointParams diff --git a/packages/smithy-http/tests/unit/aio/test_http.py b/packages/smithy-http/tests/unit/aio/test_http.py index 1bcb6520a..815814f5e 100644 --- a/packages/smithy-http/tests/unit/aio/test_http.py +++ b/packages/smithy-http/tests/unit/aio/test_http.py @@ -2,6 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 from smithy_core import URI from smithy_core.aio.utils import async_list + from smithy_http import Field, Fields from smithy_http.aio import HTTPRequest, HTTPResponse diff --git a/packages/smithy-http/tests/unit/aio/test_restjson.py b/packages/smithy-http/tests/unit/aio/test_restjson.py index fe55dd3ec..4f10fa467 100644 --- a/packages/smithy-http/tests/unit/aio/test_restjson.py +++ b/packages/smithy-http/tests/unit/aio/test_restjson.py @@ -7,6 +7,7 @@ import pytest from smithy_core.aio.utils import async_list from smithy_core.documents import DocumentValue + from smithy_http import tuples_to_fields from smithy_http.aio import HTTPResponse from smithy_http.aio.restjson import parse_rest_json_error_info diff --git a/packages/smithy-http/tests/unit/test_fields.py b/packages/smithy-http/tests/unit/test_fields.py index 884c9d105..a368fe221 100644 --- a/packages/smithy-http/tests/unit/test_fields.py +++ b/packages/smithy-http/tests/unit/test_fields.py @@ -5,6 +5,7 @@ # mypy: allow-incomplete-defs import pytest + from smithy_http import Field, Fields from smithy_http.interfaces import FieldPosition diff --git a/packages/smithy-http/tests/unit/test_utils.py b/packages/smithy-http/tests/unit/test_utils.py index e3bb9af82..6322d9a75 100644 --- a/packages/smithy-http/tests/unit/test_utils.py +++ b/packages/smithy-http/tests/unit/test_utils.py @@ -2,6 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 import pytest from smithy_core.exceptions import SmithyException + from smithy_http.utils import join_query_params, split_header diff --git a/packages/smithy-json/pyproject.toml b/packages/smithy-json/pyproject.toml index 3f7c971b3..16d5e3eaf 100644 --- a/packages/smithy-json/pyproject.toml +++ b/packages/smithy-json/pyproject.toml @@ -17,3 +17,6 @@ build-backend = "hatchling.build" exclude = [ "tests", ] + +[tool.ruff] +src = ["src"] diff --git a/packages/smithy-json/tests/unit/__init__.py b/packages/smithy-json/tests/unit/__init__.py index 40a31a27b..92c71b7b2 100644 --- a/packages/smithy-json/tests/unit/__init__.py +++ b/packages/smithy-json/tests/unit/__init__.py @@ -19,6 +19,7 @@ from smithy_core.serializers import ShapeSerializer from smithy_core.shapes import ShapeID, ShapeType from smithy_core.traits import Trait + from smithy_json._private.traits import JSON_NAME, TIMESTAMP_FORMAT SPARSE_TRAIT = Trait(id=ShapeID("smithy.api#sparse")) diff --git a/packages/smithy-json/tests/unit/test_deserializers.py b/packages/smithy-json/tests/unit/test_deserializers.py index cee2fcd27..264bc04c6 100644 --- a/packages/smithy-json/tests/unit/test_deserializers.py +++ b/packages/smithy-json/tests/unit/test_deserializers.py @@ -14,6 +14,7 @@ STRING, TIMESTAMP, ) + from smithy_json import JSONCodec from . import ( diff --git a/packages/smithy-json/tests/unit/test_serializers.py b/packages/smithy-json/tests/unit/test_serializers.py index 1eb504b4f..82b525f2e 100644 --- a/packages/smithy-json/tests/unit/test_serializers.py +++ b/packages/smithy-json/tests/unit/test_serializers.py @@ -14,6 +14,7 @@ STRING, TIMESTAMP, ) + from smithy_json import JSONCodec from . import (