MCPcopy Create free account
hub / github.com/anomalyco/opencode-sdk-python / transform

Function transform

src/opencode_ai/_utils/_transform.py:90–110  ·  view source on GitHub ↗

Transform dictionaries based off of type information from the given type, for example: ```py class Params(TypedDict, total=False): card_id: Required[Annotated[str, PropertyInfo(alias="cardID")]] transformed = transform({"card_id": " "}, Params) # {'cardID': '<my

(
    data: _T,
    expected_type: object,
)

Source from the content-addressed store, hash-verified

88
89# Wrapper over _transform_recursive providing fake types
90def transform(
91 data: _T,
92 expected_type: object,
93) -> _T:
94 """Transform dictionaries based off of type information from the given type, for example:
95
96 ```py
97 class Params(TypedDict, total=False):
98 card_id: Required[Annotated[str, PropertyInfo(alias="cardID")]]
99
100
101 transformed = transform({"card_id": "<my card ID>"}, Params)
102 # {'cardID': '<my card ID>'}
103 ```
104
105 Any keys / data that does not have type information given will be included as is.
106
107 It should be noted that the transformations that this function does are not represented in the type system.
108 """
109 transformed = _transform_recursive(data, annotation=cast(type, expected_type))
110 return cast(_T, transformed)
111
112
113@lru_cache(maxsize=8096)

Callers 1

maybe_transformFunction · 0.70

Calls 1

_transform_recursiveFunction · 0.85

Tested by

no test coverage detected