MCPcopy
hub / github.com/openai/openai-python / transform

Function transform

src/openai/_utils/_transform.py:92–112  ·  src/openai/_utils/_transform.py::transform

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": "<my card ID>"}, Params) # {'cardID': '<my

(
    data: _T,
    expected_type: object,
)

Source from the content-addressed store, hash-verified

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

Callers 1

maybe_transformFunction · 0.70

Calls 1

_transform_recursiveFunction · 0.85

Tested by

no test coverage detected