Skip to content

Commit c435dbf

Browse files
Run ruff with updated config
1 parent 230bea7 commit c435dbf

File tree

77 files changed

+220
-262
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+220
-262
lines changed

packages/aws-event-stream/src/aws_event_stream/_private/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
# SPDX-License-Identifier: Apache-2.0
33
from smithy_core.schemas import Schema
4-
54
from smithy_core.traits import EventPayloadTrait
65

76
INITIAL_REQUEST_EVENT_TYPE = "initial-request"

packages/aws-event-stream/src/aws_event_stream/_private/deserializers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
)
1212
from smithy_core.schemas import Schema
1313
from smithy_core.shapes import ShapeType
14+
from smithy_core.traits import EventHeaderTrait
1415
from smithy_core.utils import expect_type
1516

1617
from ..events import HEADERS_DICT, Event
@@ -20,7 +21,6 @@
2021
INITIAL_RESPONSE_EVENT_TYPE,
2122
get_payload_member,
2223
)
23-
from smithy_core.traits import EventHeaderTrait
2424

2525
logger = logging.getLogger(__name__)
2626

packages/aws-event-stream/src/aws_event_stream/_private/serializers.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515
SpecificShapeSerializer,
1616
)
1717
from smithy_core.shapes import ShapeType
18+
from smithy_core.traits import ErrorTrait, EventHeaderTrait, MediaTypeTrait
1819

19-
from ..events import EventHeaderEncoder, EventMessage, HEADER_VALUE, Short, Byte, Long
20+
from ..events import HEADER_VALUE, Byte, EventHeaderEncoder, EventMessage, Long, Short
2021
from ..exceptions import InvalidHeaderValue
2122
from . import (
2223
INITIAL_REQUEST_EVENT_TYPE,
2324
INITIAL_RESPONSE_EVENT_TYPE,
2425
get_payload_member,
2526
)
26-
from smithy_core.traits import ErrorTrait, EventHeaderTrait, MediaTypeTrait
2727

2828
logger = logging.getLogger(__name__)
2929

packages/aws-event-stream/src/aws_event_stream/aio/__init__.py

+9-12
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,27 @@
33
import asyncio
44
import logging
55
from collections.abc import Callable
6+
from typing import Protocol
67

7-
from smithy_core.aio.interfaces import AsyncByteStream
8+
from smithy_core.aio.interfaces import AsyncByteStream, AsyncWriter
9+
from smithy_core.aio.interfaces.eventstream import EventPublisher, EventReceiver
810
from smithy_core.codecs import Codec
911
from smithy_core.deserializers import DeserializeableShape, ShapeDeserializer
1012
from smithy_core.exceptions import ExpectationNotMetException
1113
from smithy_core.serializers import SerializeableShape
12-
from smithy_core.aio.interfaces.eventstream import EventPublisher, EventReceiver
13-
from smithy_core.aio.interfaces import AsyncWriter
1414

15-
from .._private.serializers import EventSerializer as _EventSerializer
1615
from .._private.deserializers import EventDeserializer as _EventDeserializer
16+
from .._private.serializers import EventSerializer as _EventSerializer
1717
from ..events import Event, EventHeaderEncoder, EventMessage
1818
from ..exceptions import EventError
1919

20-
from typing import Protocol
21-
2220
logger = logging.getLogger(__name__)
2321

2422

2523
class EventSigner(Protocol):
2624
"""A signer to manage credentials and EventMessages for an Event Stream lifecyle."""
2725

28-
def sign_event(
26+
async def sign_event(
2927
self,
3028
*,
3129
event_message: EventMessage,
@@ -50,7 +48,7 @@ def __init__(
5048

5149
async def send(self, event: E) -> None:
5250
if self._closed:
53-
raise IOError("Attempted to write to closed stream.")
51+
raise OSError("Attempted to write to closed stream.")
5452
logger.debug("Preparing to publish event: %s", event)
5553
event.serialize(self._serializer)
5654
result = self._serializer.get_result()
@@ -60,19 +58,18 @@ async def send(self, event: E) -> None:
6058
)
6159
if self._signer is not None:
6260
encoder = self._serializer.event_header_encoder_cls
63-
result = await self._signer.sign_event( # type: ignore
61+
result = await self._signer.sign_event(
6462
event_message=result,
6563
event_encoder_cls=encoder,
6664
)
6765

68-
assert isinstance(result, EventMessage)
6966
encoded_result = result.encode()
7067
try:
7168
logger.debug("Publishing serialized event: %s", result)
7269
await self._writer.write(encoded_result)
7370
except Exception as e:
7471
await self.close()
75-
raise IOError("Failed to write to stream.") from e
72+
raise OSError("Failed to write to stream.") from e
7673

7774
async def close(self) -> None:
7875
if self._closed:
@@ -111,7 +108,7 @@ async def receive(self) -> E | None:
111108
except Exception as e:
112109
await self.close()
113110
if not isinstance(e, EventError):
114-
raise IOError("Failed to read from stream.") from e
111+
raise OSError("Failed to read from stream.") from e
115112
raise
116113

117114
if event is None:

packages/aws-event-stream/tests/unit/_private/__init__.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from dataclasses import dataclass
55
from typing import Any, ClassVar, Literal, Self
66

7+
from aws_event_stream.events import Byte, EventMessage, Long, Short
78
from smithy_core.deserializers import ShapeDeserializer
89
from smithy_core.exceptions import SmithyException
910
from smithy_core.prelude import (
@@ -20,15 +21,13 @@
2021
from smithy_core.serializers import ShapeSerializer
2122
from smithy_core.shapes import ShapeID, ShapeType
2223
from smithy_core.traits import (
24+
ErrorTrait,
2325
EventHeaderTrait,
2426
EventPayloadTrait,
25-
ErrorTrait,
2627
RequiredTrait,
2728
StreamingTrait,
2829
)
2930

30-
from aws_event_stream.events import Byte, EventMessage, Long, Short
31-
3231
EVENT_HEADER_TRAIT = EventHeaderTrait()
3332
EVENT_PAYLOAD_TRAIT = EventPayloadTrait()
3433
ERROR_TRAIT = ErrorTrait("client")

packages/aws-event-stream/tests/unit/_private/test_deserializers.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44
from typing import Any
55

66
import pytest
7-
from smithy_core.aio.types import AsyncBytesReader
8-
from smithy_core.deserializers import DeserializeableShape
9-
from smithy_json import JSONCodec
10-
11-
from aws_event_stream.aio import AWSEventReceiver
127
from aws_event_stream._private.deserializers import EventDeserializer
8+
from aws_event_stream.aio import AWSEventReceiver
139
from aws_event_stream.events import Event, EventMessage
1410
from aws_event_stream.exceptions import UnmodeledEventError
11+
from smithy_core.aio.types import AsyncBytesReader
12+
from smithy_core.deserializers import DeserializeableShape
13+
from smithy_json import JSONCodec
1514

1615
from . import (
1716
EVENT_STREAM_SERDE_CASES,

packages/aws-event-stream/tests/unit/_private/test_serializers.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
from typing import Any
44

55
import pytest
6-
from smithy_core.serializers import SerializeableShape
7-
from smithy_core.aio.types import AsyncBytesProvider
8-
from smithy_json import JSONCodec
9-
10-
from aws_event_stream.aio import AWSEventPublisher
116
from aws_event_stream._private.serializers import EventSerializer
7+
from aws_event_stream.aio import AWSEventPublisher
128
from aws_event_stream.events import EventMessage
9+
from smithy_core.aio.types import AsyncBytesProvider
10+
from smithy_core.serializers import SerializeableShape
11+
from smithy_json import JSONCodec
1312

1413
from . import EVENT_STREAM_SERDE_CASES, INITIAL_REQUEST_CASE, INITIAL_RESPONSE_CASE
1514

packages/aws-event-stream/tests/unit/test_events.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
from io import BytesIO
77

88
import pytest
9-
from smithy_core.aio.types import AsyncBytesReader
10-
119
from aws_event_stream.events import (
1210
MAX_HEADER_VALUE_BYTE_LENGTH,
1311
MAX_HEADERS_LENGTH,
@@ -31,6 +29,7 @@
3129
InvalidIntegerValue,
3230
InvalidPayloadLength,
3331
)
32+
from smithy_core.aio.types import AsyncBytesReader
3433

3534
EMPTY_MESSAGE = (
3635
(

packages/aws-sdk-signers/src/aws_sdk_signers/__init__.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
such as AioHTTP, Curl, Postman, Requests, urllib3, etc."""
55

66
from __future__ import annotations
7+
78
import importlib.metadata
89

910
from ._http import URI, AWSRequest, Field, Fields
1011
from ._identity import AWSCredentialIdentity
1112
from ._io import AsyncBytesReader
1213
from .signers import (
13-
AsyncSigV4Signer,
1414
AsyncEventSigner,
15+
AsyncSigV4Signer,
1516
SigV4Signer,
1617
SigV4SigningProperties,
1718
)
@@ -20,14 +21,14 @@
2021
__version__ = importlib.metadata.version("aws-sdk-signers")
2122

2223
__all__ = (
23-
"AsyncBytesReader",
24-
"AsyncSigV4Signer",
25-
"AsyncEventSigner",
24+
"URI",
2625
"AWSCredentialIdentity",
2726
"AWSRequest",
27+
"AsyncBytesReader",
28+
"AsyncEventSigner",
29+
"AsyncSigV4Signer",
2830
"Field",
2931
"Fields",
3032
"SigV4Signer",
3133
"SigV4SigningProperties",
32-
"URI",
3334
)

packages/aws-sdk-signers/src/aws_sdk_signers/_http.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def __init__(
3939
kind: interfaces_http.FieldPosition = interfaces_http.FieldPosition.HEADER,
4040
):
4141
self.name = name
42-
self.values: list[str] = [val for val in values] if values is not None else []
42+
self.values: list[str] = list(values) if values is not None else []
4343
self.kind = kind
4444

4545
def add(self, value: str) -> None:
@@ -114,7 +114,7 @@ def __init__(
114114
:param encoding: The string encoding to be used when converting the ``Field``
115115
name and value from ``str`` to ``bytes`` for transmission.
116116
"""
117-
init_fields = [fld for fld in initial] if initial is not None else []
117+
init_fields = list(initial) if initial is not None else []
118118
init_field_names = [self._normalize_field_name(fld.name) for fld in init_fields]
119119
fname_counter = Counter(init_field_names)
120120
repeated_names_exist = (

packages/aws-sdk-signers/src/aws_sdk_signers/exceptions.py

-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ class AWSSDKWarning(UserWarning): ...
88
class BaseAWSSDKException(Exception):
99
"""Top-level exception to capture SDK-related errors."""
1010

11-
...
12-
1311

1412
class MissingExpectedParameterException(BaseAWSSDKException, ValueError):
1513
"""Some APIs require specific signing properties to be present."""
16-
17-
...

packages/aws-sdk-signers/src/aws_sdk_signers/interfaces/events.py

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from collections.abc import Mapping
99
from typing import Protocol
1010

11-
1211
type HEADER_VALUE = bool | int | bytes | str | datetime.datetime | uuid.UUID
1312
"""A union of valid value types for event headers."""
1413

packages/aws-sdk-signers/src/aws_sdk_signers/signers.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
# SPDX-License-Identifier: Apache-2.0
3-
3+
# ruff: noqa: S101
44
import asyncio
55
import datetime
66
import hmac
@@ -11,18 +11,18 @@
1111
from collections.abc import AsyncIterable, Iterable
1212
from copy import deepcopy
1313
from hashlib import sha256
14-
from typing import Required, TypedDict, TYPE_CHECKING
14+
from typing import TYPE_CHECKING, Required, TypedDict
1515
from urllib.parse import parse_qsl, quote
1616

17-
from .interfaces.io import AsyncSeekable, Seekable
1817
from ._http import URI, AWSRequest, Field
1918
from ._identity import AWSCredentialIdentity
20-
from .interfaces.identity import AWSCredentialsIdentity as _AWSCredentialsIdentity
2119
from ._io import AsyncBytesReader
2220
from .exceptions import AWSSDKWarning, MissingExpectedParameterException
21+
from .interfaces.identity import AWSCredentialsIdentity as _AWSCredentialsIdentity
22+
from .interfaces.io import AsyncSeekable, Seekable
2323

2424
if TYPE_CHECKING:
25-
from .interfaces.events import EventMessage, EventHeaderEncoder
25+
from .interfaces.events import EventHeaderEncoder, EventMessage
2626

2727
HEADERS_EXCLUDED_FROM_SIGNING: tuple[str, ...] = (
2828
"accept",

packages/smithy-aws-core/src/smithy_aws_core/aio/protocols.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
from typing import Final
22

3-
from smithy_aws_core.traits import RestJson1Trait
4-
from smithy_http.aio.protocols import HttpBindingClientProtocol
53
from smithy_core.codecs import Codec
64
from smithy_core.shapes import ShapeID
5+
from smithy_http.aio.protocols import HttpBindingClientProtocol
76
from smithy_json import JSONCodec
87

8+
from ..traits import RestJson1Trait
9+
910

1011
class RestJsonClientProtocol(HttpBindingClientProtocol):
1112
"""An implementation of the aws.protocols#restJson1 protocol."""

packages/smithy-aws-core/src/smithy_aws_core/auth/sigv4.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
from dataclasses import dataclass
44
from typing import Protocol
55

6-
from smithy_aws_core.identity import AWSCredentialsIdentity
6+
from aws_sdk_signers import AsyncSigV4Signer, SigV4SigningProperties
77
from smithy_core.aio.interfaces.identity import IdentityResolver
88
from smithy_core.exceptions import SmithyIdentityException
99
from smithy_core.interfaces.identity import IdentityProperties
1010
from smithy_http.aio.interfaces.auth import HTTPAuthScheme, HTTPSigner
11-
from aws_sdk_signers import SigV4SigningProperties, AsyncSigV4Signer
11+
12+
from ..identity import AWSCredentialsIdentity
1213

1314

1415
class SigV4Config(Protocol):
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
# SPDX-License-Identifier: Apache-2.0
33
from .environment import EnvironmentCredentialsResolver
4-
from .static import StaticCredentialsResolver
54
from .imds import IMDSCredentialsResolver
5+
from .static import StaticCredentialsResolver
66

77
__all__ = (
88
"EnvironmentCredentialsResolver",
9-
"StaticCredentialsResolver",
109
"IMDSCredentialsResolver",
10+
"StaticCredentialsResolver",
1111
)

packages/smithy-aws-core/src/smithy_aws_core/credentials_resolvers/environment.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
# SPDX-License-Identifier: Apache-2.0
33
import os
44

5-
from smithy_aws_core.identity import AWSCredentialsIdentity
65
from smithy_core.aio.interfaces.identity import IdentityResolver
76
from smithy_core.exceptions import SmithyIdentityException
87
from smithy_core.interfaces.identity import IdentityProperties
98

9+
from ..identity import AWSCredentialsIdentity
10+
1011

1112
class EnvironmentCredentialsResolver(
1213
IdentityResolver[AWSCredentialsIdentity, IdentityProperties]

0 commit comments

Comments
 (0)