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

Function _maybe_transform_key

src/openai/_utils/_transform.py:131–147  ·  view source on GitHub ↗

Transform the given `data` based on the annotations provided in `type_`. Note: this function only looks at `Annotated` types that contain `PropertyInfo` metadata.

(key: str, type_: type)

Source from the content-addressed store, hash-verified

129
130
131def _maybe_transform_key(key: str, type_: type) -> str:
132 """Transform the given `data` based on the annotations provided in `type_`.
133
134 Note: this function only looks at `Annotated` types that contain `PropertyInfo` metadata.
135 """
136 annotated_type = _get_annotated_type(type_)
137 if annotated_type is None:
138 # no `Annotated` definition for this type, no transformation needed
139 return key
140
141 # ignore the first argument as it is the actual type
142 annotations = get_args(annotated_type)[1:]
143 for annotation in annotations:
144 if isinstance(annotation, PropertyInfo) and annotation.alias is not None:
145 return annotation.alias
146
147 return key
148
149
150def _no_transform_needed(annotation: type) -> bool:

Callers 2

_transform_typeddictFunction · 0.85

Calls 2

_get_annotated_typeFunction · 0.85
get_argsFunction · 0.70

Tested by

no test coverage detected