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/src/aws_event_stream/events.py b/packages/aws-event-stream/src/aws_event_stream/events.py index cdd76d493..8d52bde65 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,13 @@ class _DecodeUtils: INT64_BYTE_FORMAT = "!q" # uint byte size to unpack format - UINT_BYTE_FORMAT: dict[_ArraySize, str] = { - 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]: @@ -749,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: dict[int, Callable[[BytesLike], tuple[HEADER_VALUE, int]]] = { - # 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-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/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/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..765e32c22 100644 --- a/packages/smithy-core/src/smithy_core/interfaces/identity.py +++ b/packages/smithy-core/src/smithy_core/interfaces/identity.py @@ -25,8 +25,6 @@ def is_expired(self) -> bool: class IdentityProperties(TypedDict): """Properties used to help determine the identity to return.""" - ... - IdentityPropertiesType = TypeVar("IdentityPropertiesType", bound=IdentityProperties) IdentityPropertiesType_contra = TypeVar( 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-core/src/smithy_core/schemas.py b/packages/smithy-core/src/smithy_core/schemas.py index 0e725d129..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 @@ -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 dc0698ecd..350f26d5f 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 @@ -14,7 +14,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)), @@ -24,7 +24,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( @@ -32,20 +32,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_retries.py b/packages/smithy-core/tests/unit/test_retries.py index 2d68da67a..e79173f66 100644 --- a/packages/smithy-core/tests/unit/test_retries.py +++ b/packages/smithy-core/tests/unit/test_retries.py @@ -53,8 +53,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-core/tests/unit/test_types.py b/packages/smithy-core/tests/unit/test_types.py index a478aad31..b7c48b697 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 @@ -68,57 +68,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), ), ] @@ -128,22 +128,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 31d243d6b..dc1439a8e 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 @@ -31,14 +31,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), ), ], ) @@ -200,19 +200,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", @@ -220,7 +220,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", @@ -270,7 +270,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-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/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/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..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 "scheme" in signing_properties and signing_properties["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]) ) diff --git a/packages/smithy-http/src/smithy_http/aio/crt.py b/packages/smithy-http/src/smithy_http/aio/crt.py index 6cb635a44..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: @@ -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-http/src/smithy_http/aio/interfaces/auth.py b/packages/smithy-http/src/smithy_http/aio/interfaces/auth.py index 8c1e52624..0a40a8dad 100644 --- a/packages/smithy-http/src/smithy_http/aio/interfaces/auth.py +++ b/packages/smithy-http/src/smithy_http/aio/interfaces/auth.py @@ -23,8 +23,6 @@ class SigningProperties(TypedDict): """Additional properties loaded to modify the signing process.""" - ... - SigningPropertiesType = TypeVar("SigningPropertiesType", bound=SigningProperties) SigningPropertiesType_contra = TypeVar( 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/test_crt.py b/packages/smithy-http/tests/integration/aio/test_crt.py index caed7c7ac..54072546a 100644 --- a/packages/smithy-http/tests/integration/aio/test_crt.py +++ b/packages/smithy-http/tests/integration/aio/test_crt.py @@ -12,9 +12,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/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/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 d82feb010..92c71b7b2 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 @@ -314,7 +314,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"}'), @@ -328,19 +328,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}'), @@ -369,26 +369,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", @@ -409,7 +409,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 6bdb5f1b1..80da06ae7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -46,12 +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, SIM118, SIM401, SLOT # 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" ] +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]