geneticengine.grammar.metahandlers.parent ========================================= .. py:module:: geneticengine.grammar.metahandlers.parent Classes ------- .. autoapisummary:: geneticengine.grammar.metahandlers.parent.Parent geneticengine.grammar.metahandlers.parent.Parents Module Contents --------------- .. py:class:: Parent Bases: :py:obj:`geneticengine.grammar.metahandlers.base.MetaHandlerGenerator` The Parent(variable_names, func) function allows you to access the first matched value of variables from other classes based on the specified variable_names. .. rubric:: Example Class A: value_small : Annotated[int, IntRange(-100,0)] value_big : Annotated[int, IntRange(0,100)] value : B Class B: x : Annotated[int, Parent('value_small,value_big', lambda small, big: IntRange(small, big))] In this example, the variable x is accessing variables of the Class A by parent Metahandler. You can specify multiple names at the same time by separating them with commas. If no matching variable is found, that value will be None. In func, you must ensure that None is handled or guarantee that the result will never be None. If there are multiples parent classes matched it will choose the closest one. .. py:attribute:: name :type: str .. py:attribute:: callable :type: Callable[[Any], type] .. py:method:: validate(v) .. py:method:: generate(random, grammar, base_type, rec, dependent_values, parent_values) .. py:method:: iterate(base_type, combine_lists, rec, dependent_values) .. py:method:: __hash__() .. py:method:: get_parents() .. py:class:: Parents Bases: :py:obj:`geneticengine.grammar.metahandlers.base.MetaHandlerGenerator` The Parents(variable_names, func) function allows you to access all the matched values of variables from other classes based on the specified variable_names, returning them in a list. .. rubric:: Example Class A: value_small : Annotated[int, IntRange(-100,0)] value_big : Annotated[int, IntRange(0,100)] value : B Class B: x : Annotated[int, Parents('value_small,value_big', lambda small, big: IntRange(small[0], big[0]))] In this example, the variable x is accessing variables of the Class A by parents Metahandler. You can specify multiple names at the same time by separating them with commas. If no matching variable is found, that value will be a empty list. In func, you must ensure that empty list is handled or guarantee that the result will never be a empty list. .. py:attribute:: name :type: str .. py:attribute:: callable :type: Callable[[Any], type] .. py:method:: validate(v) .. py:method:: generate(random, grammar, base_type, rec, dependent_values, parent_values) .. py:method:: iterate(base_type, combine_lists, rec, dependent_values) .. py:method:: __hash__() .. py:method:: get_parents()