pydantic_grammar module¶
A grammar based on a pydantic model.
- class gemseo.core.grammars.pydantic_grammar.PydanticGrammar(name, model=None, **kwargs)[source]
Bases:
BaseGrammar
A grammar based on a pydantic model.
The pydantic model passed to the grammar is used to initialize the grammar defaults. Currently, changing the defaults will not update the model.
Initialize self. See help(type(self)) for accurate signature.
- Parameters:
name (str) – The name of the grammar.
model (ModelType | None) – A pydantic model. If
None
, the model will be empty.**kwargs (Any) – These arguments are not used.
- Raises:
ValueError – If the name is empty.
- is_array(name, numeric_only=False)[source]
Check if an element is an array.
- Parameters:
- Returns:
Whether the element is an array. If check_items_number is set to True, then return whether the element is an array and its items are numbers.
- Raises:
KeyError – If the element is not in the grammar.
- Return type:
- set_descriptions(descriptions)[source]
Set the properties descriptions.
- to_simple_grammar()[source]
Convert the grammar to a
SimpleGrammar
.- Returns:
A
SimpleGrammar
version of the current grammar.- Return type:
Notes
For the elements for which types definitions cannot be expressed as a unique Python type, the type is set to
None
.
- update(grammar, exclude_names=())[source]
Update the grammar from another grammar.
- Parameters:
grammar (PydanticGrammar) – The grammar to update from.
exclude_names (Iterable[str]) –
The names of the elements that shall not be updated.
By default it is set to ().
- Return type:
None
- update_from_names(names)[source]
Update the grammar from names.
The updated elements are required and bind the names to Numpy arrays.
- update_from_types(names_to_types, merge=False)[source]
Update the grammar from names bound to types.
The updated elements are required.
- from_namespaced: NamespacesMapping
The mapping from element names with namespace prefix to element names without namespace prefix.
- name: str
The name of the grammar.
- property schema: dict[str, typing.Mapping[str, typing.Union[str, float, bool, typing.Sequence[typing.Union[str, float, bool]], typing.List[typing.Union[str, float, bool, typing.Sequence[typing.Union[str, float, bool]]]], typing.Mapping[str, typing.Union[str, float, bool, typing.Sequence[typing.Union[str, float, bool]], typing.List[typing.Union[str, float, bool, typing.Sequence[typing.Union[str, float, bool]]]], ForwardRef('DictSchemaType')]]]]]
The dictionary representation of the schema.
- to_namespaced: NamespacesMapping
The mapping from element names without namespace prefix to element names with namespace prefix.