gemseo.core.grammars.simple_grammar module#

A basic grammar based on names and types.

class SimpleGrammar(name, names_to_types=None, required_names=None, **kwargs)[source]#

Bases: BaseGrammar

A grammar based on names and types with a dictionary-like interface.

The types are pure Python types, type annotations are not supported.

The grammar could be empty, in that case the data validation always pass. If the type bound to a name is None then the type of the corresponding data name is always valid.

Warning

This grammar cannot merge elements. Merging will raise an error.

Warning

A name can be prefixed by a namespace. Never add a namespace by any other means than the method add_namespace().

Notes

Contrary to the standard dictionary, the :meth:.copy method creates a deep copy.

Initialize self. See help(type(self)) for accurate signature.

Parameters:
  • name (str) -- The name of the grammar.

  • names_to_types (SimpleGrammarTypes | None) -- The mapping defining the data names as keys, and data types as values. If None, the grammar is empty.

  • required_names (Iterable[str] | None) -- The names of the required elements. If None, all the elements are required.

  • **kwargs (Any) -- These arguments are not used.

Raises:

ValueError -- If the name is empty.

to_simple_grammar()[source]#

Convert the grammar to a SimpleGrammar.

Warning

Types in simple grammars are not as precise as for other grammars. Thus data that are invalid with a given grammar may be valid with a simple grammar obtained from the current method.

Returns:

A SimpleGrammar version of the current grammar.

Return type:

Self

DATA_CONVERTER_CLASS: ClassVar[str] = 'SimpleGrammarDataConverter'#

The class or the class name of the data converter.