geneticengine.grammar.utils
Functions
Returns whether type has an annotated mutation within metadata. |
|
Returns whether type has an annotated crossover within metadata. |
|
|
Returns whether type is annotated with metadata. |
|
Returns whether a type is List[T] for any T. |
|
Returns whether a type is tuple[X, Y, ...] for any X, Y, .... |
|
Returns whether a type is x[T] for any T. |
|
Returns whether a type is List[T] for any T. |
Annotated[T, <annotations>] or List[T], this function returns |
|
When given Annotated[T, <annotations>] or List[T], this function returns |
|
When given Annotated[T, <annotations>] or List[T], this function |
|
Returns whether a node has arguments or not. |
|
|
Returns whether a class is a Protocol or AbstractBaseClass. |
|
Returns whether a node is a terminal or not, based on the list of non |
|
Returns if type is a metahandler. AnnotatedType[int, IntRange(3,10)] is |
Module Contents
- 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_tuple(ty)
Returns whether a type is tuple[X, Y, …] for any X, Y, ….
- 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.is_builtin_class_instance(obj)
- geneticengine.grammar.utils.is_metahandler(ty)
Returns if type is a metahandler. AnnotatedType[int, IntRange(3,10)] is an example of a Metahandler.
Verification is done using the __metadata__, which is the first argument of Annotated
- Parameters:
ty (type)
- Return type:
bool