geneticengine.grammar.utils

Module Contents

Functions

has_annotated_mutation(ty)

Returns whether type has an annotated mutation within metadata.

has_annotated_crossover(ty)

Returns whether type has an annotated crossover within metadata.

is_annotated(ty)

Returns whether type is annotated with metadata.

is_generic_list(ty)

Returns whether a type is List[T] for any T.

is_generic(ty)

Returns whether a type is x[T] for any T.

is_union(ty)

Returns whether a type is List[T] for any T.

get_generic_parameters(ty)

Annotated[T, <annotations>] or List[T], this function returns

get_generic_parameter(ty)

When given Annotated[T, <annotations>] or List[T], this function returns

strip_annotations(ty)

When given Annotated[T, <annotations>] or List[T], this function

has_arguments(n)

Returns whether a node has arguments or not.

get_arguments(n)

param n:

production

is_abstract(t)

Returns whether a class is a Protocol or AbstractBaseClass.

is_terminal(t, non_terminals)

Returns whether a node is a terminal or not, based on the list of non

all_init_arguments_typed(t)

strip_dependencies(s)

build_finalizers(final_callback, n_args[, per_callback])

Builds a set of functions that accumulate the arguments provided.

is_builtin_class_instance(obj)

geneticengine.grammar.utils.has_annotated_mutation(ty)

Returns whether type has an annotated mutation within metadata.

Parameters:

ty (type[Any])

geneticengine.grammar.utils.has_annotated_crossover(ty)

Returns whether type has an annotated crossover within metadata.

Parameters:

ty (type[Any])

geneticengine.grammar.utils.is_annotated(ty)

Returns whether type is annotated with metadata.

Parameters:

ty (type[Any])

geneticengine.grammar.utils.is_generic_list(ty)

Returns whether a type is List[T] for any T.

Parameters:

ty (type[Any])

geneticengine.grammar.utils.is_generic(ty)

Returns whether a type is x[T] for any T.

Parameters:

ty (type[Any])

geneticengine.grammar.utils.is_union(ty)

Returns whether a type is List[T] for any T.

Parameters:

ty (type[Any])

geneticengine.grammar.utils.get_generic_parameters(ty)

Annotated[T, <annotations>] or List[T], this function returns Dict[T,]

Parameters:

ty (type[Any])

Return type:

list[type]

geneticengine.grammar.utils.get_generic_parameter(ty)

When given Annotated[T, <annotations>] or List[T], this function returns T.

Parameters:

ty (type[Any])

Return type:

type

geneticengine.grammar.utils.strip_annotations(ty)

When given Annotated[T, <annotations>] or List[T], this function recurses with T Otherwise, it returns the parameter unchanged.

Parameters:

ty (type[Any])

Return type:

type

geneticengine.grammar.utils.has_arguments(n)

Returns whether a node has arguments or not.

Parameters:

n (Any)

Return type:

bool

geneticengine.grammar.utils.get_arguments(n)
Parameters:

n – production

Returns:

list((argname, argtype))

Return type:

list[tuple[str, type]]

geneticengine.grammar.utils.is_abstract(t)

Returns whether a class is a Protocol or AbstractBaseClass.

Parameters:

t (type)

Return type:

bool

geneticengine.grammar.utils.is_terminal(t, non_terminals)

Returns whether a node is a terminal or not, based on the list of non terminals in the grammar.

Parameters:
  • t (type)

  • non_terminals (set[type])

Return type:

bool

geneticengine.grammar.utils.all_init_arguments_typed(t)
Parameters:

t (type)

Return type:

bool

geneticengine.grammar.utils.strip_dependencies(s)
Parameters:

s (str)

Return type:

str

geneticengine.grammar.utils.build_finalizers(final_callback, n_args, per_callback=None)

Builds a set of functions that accumulate the arguments provided.

Parameters:
  • final_callback

  • n_args

  • per_callback (list[Callable[[Any], None]] | None)

Returns:

Return type:

list[Any]

geneticengine.grammar.utils.is_builtin_class_instance(obj)