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.

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.

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.