Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ lint-py: ## Runs linters and formatters on the python packages.
check-py: ## Runs checks (formatting, lints, type-checking) on the python packages.
uv run docformatter packages
uv run ruff check packages
uv run ruff format --check
uv run pyright packages


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ def _get_payload_media_type(self, schema: Schema, default: str) -> str:


class EventHeaderSerializer(SpecificShapeSerializer):

def __init__(self, encoder: EventHeaderEncoder) -> None:
self._encoder = encoder

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@


class AWSDuplexEventStream[
I: SerializeableShape, O: DeserializeableShape, R: DeserializeableShape
I: SerializeableShape,
O: DeserializeableShape,
R: DeserializeableShape,
](DuplexEventStream[I, O, R]):
"""A duplex event stream using the application/vnd.amazon.eventstream format."""

Expand Down
12 changes: 8 additions & 4 deletions packages/aws-event-stream/tests/unit/_private/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,7 @@ def serialize(self, serializer: ShapeSerializer):
serializer.write_struct(SCHEMA_EVENT_STREAM, self)

def serialize_members(self, serializer: ShapeSerializer):
serializer.write_struct(
SCHEMA_EVENT_STREAM.members["blobPayload"], self.value
)
serializer.write_struct(SCHEMA_EVENT_STREAM.members["blobPayload"], self.value)


@dataclass
Expand Down Expand Up @@ -393,7 +391,13 @@ def serialize_members(self, serializer: ShapeSerializer):
raise SmithyException("Unknown union variants may not be serialized.")


type EventStream = EventStreamMessageEvent | EventStreamPayloadEvent | EventStreamBlobPayloadEvent | EventStreamErrorEvent | EventStreamUnknownEvent
type EventStream = (
EventStreamMessageEvent
| EventStreamPayloadEvent
| EventStreamBlobPayloadEvent
| EventStreamErrorEvent
| EventStreamUnknownEvent
)


class EventStreamDeserializer:
Expand Down
10 changes: 5 additions & 5 deletions packages/aws-event-stream/tests/unit/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
b"\x00\x00\x00\x10" # total length
b"\x00\x00\x00\x00" # headers length
b"\x05\xc2\x48\xeb" # prelude crc
b"\x7D\x98\xc8\xff" # message crc
b"\x7d\x98\xc8\xff" # message crc
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dang, ruff is really this pedantic huh

),
Event(
prelude=EventPrelude(
Expand Down Expand Up @@ -407,7 +407,7 @@
CORRUPTED_HEADERS_LENGTH = (
(
b"\x00\x00\x00\x3d" # total length
b"\xFF\x00\x01\x02" # headers length
b"\xff\x00\x01\x02" # headers length
b"\x07\xfd\x83\x96" # prelude crc
b"\x0ccontent-type\x07\x00\x10application/json" # headers
b"{'foo':'bar'}" # payload
Expand Down Expand Up @@ -443,7 +443,7 @@
(
b"\x00\x00\x00\x1d" # total length
b"\x00\x00\x00\x00" # headers length
b"\xfd\x52\x8c\x5A" # prelude crc
b"\xfd\x52\x8c\x5a" # prelude crc
b"{'foo':'bar'\x8d" # payload
b"\xc3\x65\x39\x36" # message crc
),
Expand All @@ -464,11 +464,11 @@
INVALID_HEADERS_LENGTH = (
(
b"\x00\x00\x00\x3d" # total length
b"\xFF\x00\x01\x02" # headers length
b"\xff\x00\x01\x02" # headers length
b"\x15\x83\xf5\xc2" # prelude crc
b"\x0ccontent-type\x07\x00\x10application/json" # headers
b"{'foo':'bar'}" # payload
b"\x2F\x37\x7f\x5d" # message crc
b"\x2f\x37\x7f\x5d" # message crc
),
InvalidHeadersLength,
)
Expand Down
6 changes: 2 additions & 4 deletions packages/smithy-core/src/smithy_core/aio/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async def read(self, size: int = -1) -> bytes:
if self._closed or not self._data:
raise ValueError("I/O operation on closed file.")

if isinstance(self._data, BytesReader) and not iscoroutinefunction( # type: ignore - TODO(pyright)
if isinstance(self._data, BytesReader) and not iscoroutinefunction( # type: ignore - TODO(pyright)
self._data.read
):
# Python's runtime_checkable can't actually tell the difference between
Expand Down Expand Up @@ -135,7 +135,7 @@ def __init__(self, data: StreamingBlob):
if isinstance(data, bytes | bytearray):
self._buffer = BytesIO(data)
self._data_source = None
elif isinstance(data, AsyncByteStream) and iscoroutinefunction(data.read): # type: ignore - TODO(pyright)
elif isinstance(data, AsyncByteStream) and iscoroutinefunction(data.read): # type: ignore - TODO(pyright)
# Note that we need that iscoroutine check because python won't actually check
# whether or not the read function is async.
self._buffer = BytesIO()
Expand Down Expand Up @@ -321,7 +321,6 @@ async def write(self, data: bytes) -> None:
# Acquire a lock on the data buffer, releasing it automatically when the
# block exits.
async with self._data_condition:

# Wait for the number of chunks in the buffer to be less than the
# specified maximum. This also releases the lock until that condition
# is met.
Expand Down Expand Up @@ -407,7 +406,6 @@ async def __anext__(self) -> bytes:
# Acquire a lock on the data buffer, releasing it automatically when the
# block exits.
async with self._data_condition:

# Wait for the stream to be closed or for the data buffer to be non-empty.
# This also releases the lock until that condition is met.
await self._data_condition.wait_for(
Expand Down
6 changes: 3 additions & 3 deletions packages/smithy-core/src/smithy_core/codecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ def serialize(self, shape: "SerializeableShape") -> bytes:
stream.seek(0)
return stream.read()

def deserialize[
S: DeserializeableShape
](self, source: bytes | BytesReader, shape: type[S]) -> S:
def deserialize[S: DeserializeableShape](
self, source: bytes | BytesReader, shape: type[S]
) -> S:
"""Deserialize bytes into a shape.
:param source: The bytes to deserialize.
Expand Down
1 change: 1 addition & 0 deletions packages/smithy-core/src/smithy_core/rfc3986.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
https://github.com/python-hyper/rfc3986/blob/main/src/rfc3986/abnf_regexp.py
https://github.com/python-hyper/rfc3986/blob/main/src/rfc3986/misc.py
"""

import re

# #########################
Expand Down
1 change: 0 additions & 1 deletion packages/smithy-core/tests/unit/aio/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,6 @@ async def test_aexit_flushes() -> None:
# Use the provider in a context manager. When this exits, it should flush
# and close the provider.
async with provider:

# Write some data to the provider.
await provider.write(b"foo")

Expand Down
4 changes: 3 additions & 1 deletion packages/smithy-core/tests/unit/test_documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,9 @@ def test_document_serializer(given: Any, expected: Document):
if v is None:
map_serializer.entry(k, lambda vs: vs.write_null(member_schema))
else:
map_serializer.entry(k, lambda vs: vs.write_string(member_schema, v)) # type: ignore
map_serializer.entry(
k, lambda vs: vs.write_string(member_schema, v)
) # type: ignore
case DocumentSerdeShape():
given.serialize(serializer)
case _:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ async def main():
input = StreamMessagesInput(chat_room="aws-python-sdk", username="hunter7")

async with client.stream_messages(input=input) as stream:
stream.input_stream.send(MessageStreamMessage("Chat logger starting up."))
stream.input_stream.send(
MessageStreamMessage("Chat logger starting up.")
)
response_task = asyncio.create_task(handle_output(stream))
stream.input_stream.send(MessageStreamMessage("Chat logger active."))
await response_handler
Expand All @@ -97,7 +99,9 @@ async def handle_output(stream: EventStream) -> None:
return
case _:
stream.input_stream.send(
MessageStreamMessage("Unknown message type received. Shutting down.")
MessageStreamMessage(
"Unknown message type received. Shutting down."
)
)
return
"""
Expand Down Expand Up @@ -193,7 +197,9 @@ async def main():
input = PublishMessagesInput(chat_room="aws-python-sdk", username="hunter7")

async with client.publish_messages(input=input) as stream:
stream.input_stream.send(MessageStreamMessage("High severity ticket alert!"))
stream.input_stream.send(
MessageStreamMessage("High severity ticket alert!")
)
await stream.await_output()
"""

Expand Down
4 changes: 3 additions & 1 deletion packages/smithy-json/tests/unit/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ def test_json_serializer(given: Any, expected: bytes) -> None:
if v is None:
map_serializer.entry(k, lambda vs: vs.write_null(member_schema))
else:
map_serializer.entry(k, lambda vs: vs.write_string(member_schema, v)) # type: ignore
map_serializer.entry(
k, lambda vs: vs.write_string(member_schema, v)
) # type: ignore
case SerdeShape():
given.serialize(serializer)
case _:
Expand Down