MCPcopy
hub / github.com/anthropics/anthropic-sdk-python / _construct_field

Function _construct_field

src/anthropic/_models.py:495–507  ·  view source on GitHub ↗
(value: object, field: FieldInfo, key: str)

Source from the content-addressed store, hash-verified

493
494
495def _construct_field(value: object, field: FieldInfo, key: str) -> object:
496 if value is None:
497 return field_get_default(field)
498
499 if PYDANTIC_V1:
500 type_ = cast(type, field.outer_type_) # type: ignore
501 else:
502 type_ = field.annotation # type: ignore
503
504 if type_ is None:
505 raise RuntimeError(f"Unexpected field type is None for {key}")
506
507 return construct_type(value=value, type_=type_, metadata=getattr(field, "metadata", None))
508
509
510def _get_extra_fields_type(cls: type[pydantic.BaseModel]) -> type | None:

Callers 1

constructMethod · 0.85

Calls 2

field_get_defaultFunction · 0.85
construct_typeFunction · 0.85

Tested by

no test coverage detected