Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 3 additions & 1 deletion codegen-output-py/types/.smithy-python-manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"files": {
"src/example_types/_private/schemas.py": "d0f35e8979c4aa9d49a1d9c0c8efeb860420bc0ceab3ba3edcc9488c053e9110"
"src/example_types/_private/schemas.py": "1d708d275049f3f4a86b343c3f38104ef4a7e5bf749a27cd1a490c95c8f9db59",
"src/example_types/models.py": "51aadd47e9971f2b44fabd47e81e4b04d7156aa61b64454b39f4b6d47603ab45",
"src/example_types/models.pyi": "31c14804662d43c11fc6c61d0a49244e5e606b65aadb774df913f6a26e1b135a"
},
"version": 1
}
40 changes: 27 additions & 13 deletions codegen-output-py/types/src/example_types/_private/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,16 @@
_s26 = "choice"
_s27 = "status"
_s28 = "code"
_s29 = "GetExampleOutput"
_s30 = "smithy.api#output"
_s31 = "ExampleError"
_s32 = "smithy.api#error"
_s33 = "client"
_s34 = "message"
_s35 = "retryAfterSeconds"
_s29 = "EventStream"
_s30 = "smithy.api#streaming"
_s31 = "GetExampleOutput"
_s32 = "smithy.api#output"
_s33 = "events"
_s34 = "ExampleError"
_s35 = "smithy.api#error"
_s36 = "client"
_s37 = "message"
_s38 = "retryAfterSeconds"

GET_EXAMPLE_INPUT: StaticSchema = (
18,
Expand Down Expand Up @@ -145,29 +148,40 @@
),
)

GET_EXAMPLE_OUTPUT: StaticSchema = (
18,
EVENT_STREAM: StaticSchema = (
19,
n0,
_s29,
{_s30: None},
(n0,),
((RENAMED_EXAMPLE, 0),),
)

GET_EXAMPLE_OUTPUT: StaticSchema = (
18,
n0,
_s31,
{_s32: None},
(
n0,
_s7,
_s33,
),
(
(RENAMED_EXAMPLE, 0),
(EXAMPLE_VALUE, 0),
(EVENT_STREAM, 0),
),
)

EXAMPLE_ERROR: StaticSchema = (
18,
n0,
_s31,
{_s32: _s33},
_s34,
{_s35: _s36},
(
_s34,
_s35,
_s37,
_s38,
),
(
(3, 0),
Expand Down
79 changes: 79 additions & 0 deletions codegen-output-py/types/src/example_types/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
from __future__ import annotations

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

what is this needed for? Are we applying it unconditionally to every file?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yeah, PythonWriter adds it to every generated module. it keeps forward and recursive type annotations from being evaluated at import time


from smithy_core._dynamic_models import ModelRegistry
from smithy_core.exceptions import ModeledError

from ._private import schemas


class ServiceError(ModeledError):
"""
Base error for all errors in the service.

Some exceptions do not extend from this class, including synthetic,
implicit, and shared exception types.
"""


_MODEL_INDEX = {
"GetExampleInput": "GET_EXAMPLE_INPUT",
"GetExampleOutput": "GET_EXAMPLE_OUTPUT",
"ExampleError": "EXAMPLE_ERROR",
"RenamedExample": "RENAMED_EXAMPLE",
"ExampleValue": "EXAMPLE_VALUE",
"ExampleValueText": "EXAMPLE_VALUE",
"ExampleValueNumber": "EXAMPLE_VALUE",
"ExampleValueEmpty": "EXAMPLE_VALUE",
"ExampleValueUnknown": "EXAMPLE_VALUE",
"EventStream": "EVENT_STREAM",
"EventStreamExample": "EVENT_STREAM",
"EventStreamUnknown": "EVENT_STREAM",
"Status": "STATUS",
"Code": "CODE",
}

_RENAMES = {
"RenamedExample": "RENAMED_EXAMPLE",
"ExampleValue": "EXAMPLE_VALUE",
}

_TARGET_NAMES = {
"example#Example": "RenamedExample",
"example#Value": "ExampleValue",
}

_MODEL_NAMES = (*tuple(_MODEL_INDEX), "Unit")
__all__ = ("ServiceError", *_MODEL_NAMES)


_registry = ModelRegistry(
schemas,
renames=_RENAMES,
index=_MODEL_INDEX,
target_names=_TARGET_NAMES,
shape_names=frozenset(
{
"Code",
"EventStream",
"ExampleError",
"ExampleValue",
"GetExampleInput",
"GetExampleOutput",
"RenamedExample",
"Status",
"Unit",
}
),
service_error="ServiceError",
)
del schemas, ModelRegistry, ModeledError


def __getattr__(name: str):
value = _registry.build(name)
globals()[name] = value
return value


def __dir__() -> list[str]:
return sorted({*globals(), *__all__})
160 changes: 160 additions & 0 deletions codegen-output-py/types/src/example_types/models.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
from __future__ import annotations

from dataclasses import dataclass
from enum import IntEnum, StrEnum
from typing import Self

from smithy_core.deserializers import ShapeDeserializer
from smithy_core.documents import Document
from smithy_core.exceptions import ModeledError
from smithy_core.response import ResponseMetadata
from smithy_core.serializers import ShapeSerializer
from smithy_core.types import UnknownEnumMixin

__all__ = [
"Code",
"EventStream",
"EventStreamExample",
"EventStreamUnknown",
"ExampleError",
"ExampleValue",
"ExampleValueEmpty",
"ExampleValueNumber",
"ExampleValueText",
"ExampleValueUnknown",
"GetExampleInput",
"GetExampleOutput",
"RenamedExample",
"ServiceError",
"Status",
"Unit",
]

class _SerdeShape:
def serialize(self, serializer: ShapeSerializer) -> None: ...
def serialize_members(self, serializer: ShapeSerializer) -> None: ...
@classmethod
def deserialize(cls, deserializer: ShapeDeserializer) -> Self: ...

class ServiceError(ModeledError):
"""
Base error for all errors in the service.

Some exceptions do not extend from this class, including synthetic,
implicit, and shared exception types.
"""

@dataclass(kw_only=True)
class GetExampleInput(_SerdeShape):
"Input for retrieving an example."

id: str | None = ...

@dataclass(kw_only=True)
class GetExampleOutput(_SerdeShape):
"Dataclass for GetExampleOutput structure."

example: RenamedExample | None = ...
value: ExampleValue | None = ...
response_metadata: ResponseMetadata = ...
"""
Metadata about the response that produced this output.

Use this to recover the request identifiers a service's support team
needs in order to investigate a call. Members of the metadata are
individually optional.
"""

@dataclass(kw_only=True)
class ExampleError(ServiceError, _SerdeShape):
"An example modeled error."

retry_after_seconds: int | None = ...
response_metadata: ResponseMetadata = ...
"""
Metadata about the response that produced this output.

Use this to recover the request identifiers a service's support team
needs in order to investigate a call. Members of the metadata are
individually optional.
"""

@dataclass(kw_only=True)
class RenamedExample(_SerdeShape):
"A representative generated structure."

name: str
"The example name."
count: int | None = ...
tags: list[str] | None = ...
attributes: dict[str, Document] | None = ...
choice: ExampleValue | None = ...
status: str | None = ...
code: int | None = ...

@dataclass
class ExampleValueText(_SerdeShape):
value: str

@dataclass
class ExampleValueNumber(_SerdeShape):
value: int

@dataclass
class ExampleValueEmpty(_SerdeShape):
value: Unit

@dataclass
class ExampleValueUnknown(_SerdeShape):
"""
Represents an unknown variant.

If you receive this value, you will need to update your library to
receive the parsed value.

This value may not be deliberately sent.
"""

tag: str

ExampleValue = (
ExampleValueText | ExampleValueNumber | ExampleValueEmpty | ExampleValueUnknown
)
"A representative generated union."

class _ExampleValueDeserializer:
def deserialize(self, deserializer: ShapeDeserializer) -> ExampleValue: ...

@dataclass
class EventStreamExample(_SerdeShape):
value: RenamedExample

@dataclass
class EventStreamUnknown(_SerdeShape):
"""
Represents an unknown variant.

If you receive this value, you will need to update your library to
receive the parsed value.

This value may not be deliberately sent.
"""

tag: str

EventStream = EventStreamExample | EventStreamUnknown

class _EventStreamDeserializer:
def deserialize(self, deserializer: ShapeDeserializer) -> EventStream: ...

class Status(UnknownEnumMixin, StrEnum):
ACTIVE = "active"
INACTIVE = "inactive"

class Code(UnknownEnumMixin, IntEnum):
OK = 200
NOT_FOUND = 404

@dataclass(kw_only=True)
class Unit(_SerdeShape):
pass
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ class PublishEventsInput(_SerdeShape):
"""Dataclass for PublishEventsInput structure."""

channel: str | None = ...
events: PublishEventStream | None = ...

@dataclass(kw_only=True)
class PublishEventsOutput(_SerdeShape):
Expand Down Expand Up @@ -188,7 +187,6 @@ class SubscribeToEventsOutput(_SerdeShape):
"""Dataclass for SubscribeToEventsOutput structure."""

subscription_id: str | None = ...
events: SubscribeEventStream | None = ...
response_metadata: ResponseMetadata = ...
"""
Metadata about the response that produced this output.
Expand Down Expand Up @@ -261,14 +259,12 @@ class TradeEventStreamInput(_SerdeShape):
"""Dataclass for TradeEventStreamInput structure."""

session_id: str | None = ...
events: TradeEvents | None = ...

@dataclass(kw_only=True)
class TradeEventStreamOutput(_SerdeShape):
"""Dataclass for TradeEventStreamOutput structure."""

greeting: str | None = ...
events: TradeEvents | None = ...
response_metadata: ResponseMetadata = ...
"""
Metadata about the response that produced this output.
Expand Down
Loading
Loading