MCPcopy Create free account
hub / github.com/Materials-Consortia/optimade-python-tools / OptimadeField

Function OptimadeField

optimade/models/utils.py:126–165  ·  view source on GitHub ↗

A wrapper around `pydantic.Field` that adds OPTIMADE-specific field paramters `queryable`, `support` and `unit`, indicating the corresponding support level in the specification and the physical unit of the field. Arguments: support: The support level of the field itself, i.e

(
    default: "Any" = PydanticUndefined,
    *,
    support: str | SupportLevel | None = None,
    queryable: str | SupportLevel | None = None,
    unit: str | None = None,
    **kwargs,
)

Source from the content-addressed store, hash-verified

124
125
126def OptimadeField(
127 default: "Any" = PydanticUndefined,
128 *,
129 support: str | SupportLevel | None = None,
130 queryable: str | SupportLevel | None = None,
131 unit: str | None = None,
132 **kwargs,
133) -> Any:
134 """A wrapper around `pydantic.Field` that adds OPTIMADE-specific
135 field paramters `queryable`, `support` and `unit`, indicating
136 the corresponding support level in the specification and the
137 physical unit of the field.
138
139 Arguments:
140 support: The support level of the field itself, i.e. whether the field
141 can be null or omitted by an implementation.
142 queryable: The support level corresponding to the queryablility
143 of this field.
144 unit: A string describing the unit of the field.
145
146 Returns:
147 The pydantic field with extra validation provided by [`StrictField`][optimade.models.utils.StrictField].
148
149 """
150
151 # Collect non-null keyword arguments to add to the Field schema
152 if unit is not None:
153 kwargs["unit"] = unit
154
155 if queryable is not None:
156 if isinstance(queryable, str):
157 queryable = SupportLevel(queryable.lower())
158 kwargs["queryable"] = queryable
159
160 if support is not None:
161 if isinstance(support, str):
162 support = SupportLevel(support.lower())
163 kwargs["support"] = support
164
165 return StrictField(default, **kwargs)
166
167
168def anonymous_element_generator() -> "Generator[str, None, None]":

Callers 9

PersonClass · 0.90
ReferenceResourceClass · 0.90
EntryResourceClass · 0.90
SpeciesClass · 0.90
AssemblyClass · 0.90

Calls 2

SupportLevelClass · 0.85
StrictFieldFunction · 0.85

Tested by

no test coverage detected