PyTimeloop
Loading...
Searching...
No Matches
pytimeloop.timeloopfe.common.nodes copy.Node Class Reference

Base class for all nodes in the hierarchy. More...

Inheritance diagram for pytimeloop.timeloopfe.common.nodes copy.Node:
Collaboration diagram for pytimeloop.timeloopfe.common.nodes copy.Node:

Public Member Functions

 __init__ (self, *args, **kwargs)
 
 get_specifiers_from_processors (cls, "BaseSpecification" spec)
 Get the specifiers that have been set from processors.
 
 reset_specifiers_from_processors (cls, Optional[Type] processor=None)
 Reset the specifiers that have been set from processors.
 
 declare_attrs (cls, *args, **kwargs)
 Initialize the attributes of this node.
 
 reset_processor_elems (cls, Optional[Type] processor=None)
 
 recognize_all (cls, bool recognize_all=True)
 Set whether all attributes under this node should be recognized.
 
str get_tag (self)
 Get the tag of this node.
 
Iterable[Tuple[Union[str, int], Any]] items (self)
 Get iterable of (key, value) or (index, value) pairs.
 
T combine_index (self, Union[str, int] key, T value)
 Combine the value at the given key with the given value.
 
str get_name (self, Union[Set, None] seen=None)
 Get the name of this node.
 
 check_unrecognized (self, bool ignore_empty=False, ignore_should_have_been_removed_by=False)
 Check for unrecognized keys in this node and all subnodes.
 
Any recursive_apply (self, callable func, bool self_first=False, set applied_to=None)
 Apply a function to this node and all subnodes.
 
 clean_empties (self)
 Remove empty nodes from this node and all subnodes.
 
bool isempty (self)
 Return True if this node is empty.
 
bool isempty_recursive (self)
 Return True if this node or all subnodes are empty.
 
 add_attr (cls, str key_or_tag, Optional[Union[type, Tuple[type,...], Tuple[None,...], Tuple[str,...], None]] required_type=None, Any default=default_unspecified_, Optional[Callable] callfunc=None, Optional[bool] part_name_match=None, Optional[bool] no_change_key=None, Any _processor_responsible_for_removing=None, Optional[Dict[str, TypeSpecifier]] _add_checker_to=None)
 Initialize a type specifier for this class.
 
List[Tget_nodes_of_type (self, Type[T] node_type)
 Return a list of all subnodes of a given type.
 
Callable get_setter_lambda (self, Union[str, int] keytag)
 Get a function that can be used to set a value in this node.
 
Callable get_combiner_lambda (self, Union[str, int] keytag)
 Get a function that can be used to combine a value to this node.
 
List[Tuple[Any, Callable]] get_setters_for_keytag (self, str keytag, bool recursive=True)
 Get a list of tuples of the form (value, setter) for all keys/tags in this node that match the given key/tag.
 
List[Tuple[Any, Callable]] get_combiners_for_keytag (self, str keytag, bool recursive=True)
 Get a list of tuples of the form (value, combiner) for all keys/tags in this node that match the given key/tag.
 
List[Tuple[Any, Callable]] get_setters_for_type (self, Type t, bool recursive=True)
 Get a list of tuples of the form (value, setter) for all keys/tags in this node that match the given type.
 
List[Tuple[Any, Callable]] get_combiners_for_type (self, Type t, bool recursive=True)
 Get a list of tuples of the form (value, combiner) for all keys/tags in this node that match the given type.
 
 __str__ (self)
 Return the name of this node.
 
 __format__ (self, format_spec)
 Formats the name of this node.
 
bool is_defined_non_default_non_empty (self, str key)
 Returns True if the given key is defined in this node and is not the default value and is not empty.
 
Any __getitem__ (self, Union[str, int] key)
 Get the value at the given key or index.
 
 __setitem__ (self, Union[str, int] key, Any value)
 Set the value at the given key or index.
 
 parse_expressions (self, Optional[Dict[str, Any]] symbol_table=None, Optional[set] parsed_ids=None, Optional[Callable] callfunc=None)
 Parse expressions in this node and all subnodes.
 
 unique_class_name (cls)
 Return a unique name for this class.
 

Static Public Member Functions

"BaseSpecification" get_global_spec ()
 Get the global specification object.
 
 set_global_spec ("BaseSpecification" spec)
 Set the global specification object.
 
Any try_combine (Any a, Any b, Union["Node", None] innonde=None, Union[int, str, None] index=None)
 Try to combine two values.
 

Public Attributes

Node parent_node = None
 
"BaseSpecification" spec = Node.get_global_spec()
 
 logger = logging.getLogger(self.__class__.__name__)
 

Protected Member Functions

Dict[str, TypeSpecifier_get_type_specifiers (cls, "BaseSpecification" spec)
 Get the type specifiers for this node.
 
 _get_all_recognized (self)
 
Dict[Union[str, int], TypeSpecifier_get_index2checker (self, Optional[List[Tuple[str, Any]]] key2elem=None)
 
 _parse_elem (self, Union[str, int] key, TypeSpecifier check, Any value_override=None)
 
 _parse_elems (self)
 
 _parse_extra_elems (self, List[Tuple[str, Any]] key2elem)
 
 _check_unrecognized (self, ignore_empty=False, ignore_should_have_been_removed_by=False)
 
 _parse_expression (self, Union[str, int] index, Dict[str, Any] symbol_table, Optional[TypeSpecifier] checker=None)
 

Static Protected Member Functions

str _get_tag (x)
 

Protected Attributes

tuple _init_args = (args, kwargs)
 
bool _default_parse = False
 

Private Attributes

Union[int, str] __currently_parsing_index = None
 

Detailed Description

Base class for all nodes in the hierarchy.

Attributes: parent_node (Node): The parent node of the current node. spec (Specification): The global specification object. _init_args (Tuple): The arguments and keyword arguments used to initialize the node. __currently_parsing_index (Union[int, str]): The index or key currently being parsed. logger (Logger): The logger object for the node's class. _default_parse (bool): Flag indicating whether the node should be parsed using default rules.

Methods: get_specifiers_from_processors(cls, spec): Get the specifiers from processors. reset_specifiers_from_processors(cls, processor): Reset the specifiers from processors. declare_attrs(cls, *args, **kwargs): Initialize the attributes of this node. reset_processor_elems(cls, processor): Reset the processor elements. recognize_all(cls, recognize_all): Set whether all attributes under this node should be recognized. _get_type_specifiers(cls, spec): Get the type specifiers for this node. _get_all_recognized(self): Check if all attributes under this node are recognized. _get_tag(x): Get the tag of a node. get_global_spec(): Get the global specification object. set_global_spec(spec): Set the global specification object. get_tag(self): Get the tag of this node. _get_index2checker(self, key2elem): Get the index-to-checker mapping. items(self): Get an iterable of (key, value) or (index, value) pairs. combine_index(self, key, value): Combine the value at the given key with the given value. _parse_elem(self, key, check, value_override): Parse an element of the node.

Constructor & Destructor Documentation

◆ __init__()

pytimeloop.timeloopfe.common.nodes copy.Node.__init__ ( self,
* args,
** kwargs )

Member Function Documentation

◆ __format__()

pytimeloop.timeloopfe.common.nodes copy.Node.__format__ ( self,
format_spec )

Formats the name of this node.

◆ __getitem__()

Any pytimeloop.timeloopfe.common.nodes copy.Node.__getitem__ ( self,
Union[str, int] key )

Get the value at the given key or index.

Reimplemented in pytimeloop.timeloopfe.common.nodes copy.DictNode.

◆ __setitem__()

pytimeloop.timeloopfe.common.nodes copy.Node.__setitem__ ( self,
Union[str, int] key,
Any value )

Set the value at the given key or index.

Reimplemented in pytimeloop.timeloopfe.common.nodes copy.DictNode.

◆ __str__()

pytimeloop.timeloopfe.common.nodes copy.Node.__str__ ( self)

Return the name of this node.

◆ _check_unrecognized()

pytimeloop.timeloopfe.common.nodes copy.Node._check_unrecognized ( self,
ignore_empty = False,
ignore_should_have_been_removed_by = False )
protected

◆ _get_all_recognized()

pytimeloop.timeloopfe.common.nodes copy.Node._get_all_recognized ( self)
protected

◆ _get_index2checker()

Dict[Union[str, int], TypeSpecifier] pytimeloop.timeloopfe.common.nodes copy.Node._get_index2checker ( self,
Optional[List[Tuple[str, Any]]] key2elem = None )
protected

◆ _get_tag()

str pytimeloop.timeloopfe.common.nodes copy.Node._get_tag ( x)
staticprotected

◆ _get_type_specifiers()

Dict[str, TypeSpecifier] pytimeloop.timeloopfe.common.nodes copy.Node._get_type_specifiers ( cls,
"BaseSpecification" spec )
protected

Get the type specifiers for this node.

Attributes: spec (Specification): The global specification object.

Returns: Dict[str, TypeSpecifier]: The type specifiers for this node.

◆ _parse_elem()

pytimeloop.timeloopfe.common.nodes copy.Node._parse_elem ( self,
Union[str, int] key,
TypeSpecifier check,
Any value_override = None )
protected

◆ _parse_elems()

pytimeloop.timeloopfe.common.nodes copy.Node._parse_elems ( self)
protected

◆ _parse_expression()

pytimeloop.timeloopfe.common.nodes copy.Node._parse_expression ( self,
Union[str, int] index,
Dict[str, Any] symbol_table,
Optional[TypeSpecifier] checker = None )
protected

◆ _parse_extra_elems()

pytimeloop.timeloopfe.common.nodes copy.Node._parse_extra_elems ( self,
List[Tuple[str, Any]] key2elem )
protected

◆ add_attr()

pytimeloop.timeloopfe.common.nodes copy.Node.add_attr ( cls,
str key_or_tag,
Optional[ Union[type, Tuple[type, ...], Tuple[None, ...], Tuple[str, ...], None] ] required_type = None,
Any default = default_unspecified_,
Optional[Callable] callfunc = None,
Optional[bool] part_name_match = None,
Optional[bool] no_change_key = None,
Any _processor_responsible_for_removing = None,
Optional[Dict[str, TypeSpecifier]] _add_checker_to = None )

Initialize a type specifier for this class.

Args: key_or_tag: The key/tag or tag to use for this type specifier. required_type: The type of value that this type specifier will be default: The default value to use if the key/tag is not found. callfunc: A function to call on the value before returning it. part_name_match: If True, the key/tag will match if it is a substring of the actual key/tag. no_change_key: If True, a parsed key will not be changed when a partial name match is found. Otherwise, the parsed key will be changed to the actual key. _processor_responsible_for_removing: The processor that will be responsible for removing this key from the containing node, if any. _add_checker_to: The dictionary to add the checker to. If None, add the checker to the class's type specifiers.

Raises: AttributeError: If the class does not have a _param_type_specifiers attribute.

◆ check_unrecognized()

pytimeloop.timeloopfe.common.nodes copy.Node.check_unrecognized ( self,
bool ignore_empty = False,
ignore_should_have_been_removed_by = False )

Check for unrecognized keys in this node and all subnodes.

Also checks for correct types.

Args: ignore_empty (bool): Flag indicating whether to ignore empty nodes. ignore_should_have_been_removed_by (bool): Flag indicating whether to ignore nodes that should have been removed by a processor.

Raises: ParseError: If an unrecognized key is found.

Reimplemented in pytimeloop.timeloopfe.common.nodes copy.DictNode.

◆ clean_empties()

pytimeloop.timeloopfe.common.nodes copy.Node.clean_empties ( self)

Remove empty nodes from this node and all subnodes.

◆ combine_index()

T pytimeloop.timeloopfe.common.nodes copy.Node.combine_index ( self,
Union[str, int] key,
T value )

Combine the value at the given key with the given value.

If there is no value at the given key, sets the value at the given key. If there is, attempts to combine the two values.

Args: key: The key to combine. value: The value to combine.

Returns: The combined value.

◆ declare_attrs()

pytimeloop.timeloopfe.common.nodes copy.Node.declare_attrs ( cls,
* args,
** kwargs )

Initialize the attributes of this node.

◆ get_combiner_lambda()

Callable pytimeloop.timeloopfe.common.nodes copy.Node.get_combiner_lambda ( self,
Union[str, int] keytag )

Get a function that can be used to combine a value to this node.

The combiner takes one argument, the value to combine.

Args: keytag: The key or tag to combine.

Returns: A function that can be used to combine a value to this node.

◆ get_combiners_for_keytag()

List[Tuple[Any, Callable]] pytimeloop.timeloopfe.common.nodes copy.Node.get_combiners_for_keytag ( self,
str keytag,
bool recursive = True )

Get a list of tuples of the form (value, combiner) for all keys/tags in this node that match the given key/tag.

A combiner is a function that can be used to combine a value to this node.

Args: keytag: The key or tag to search for. recursive: If True, search recursively.

◆ get_combiners_for_type()

List[Tuple[Any, Callable]] pytimeloop.timeloopfe.common.nodes copy.Node.get_combiners_for_type ( self,
Type t,
bool recursive = True )

Get a list of tuples of the form (value, combiner) for all keys/tags in this node that match the given type.

A combiner is a function that can be used to combine a value in this node.

Args: t: The type to search for. recursive: If True, search recursively.

Returns: A list of tuples of the form (value, combiner) for all keys/tags in this node that match the given type.

◆ get_global_spec()

"BaseSpecification" pytimeloop.timeloopfe.common.nodes copy.Node.get_global_spec ( )
static

Get the global specification object.

◆ get_name()

str pytimeloop.timeloopfe.common.nodes copy.Node.get_name ( self,
Union[Set, None] seen = None )

Get the name of this node.

◆ get_nodes_of_type()

List[T] pytimeloop.timeloopfe.common.nodes copy.Node.get_nodes_of_type ( self,
Type[T] node_type )

Return a list of all subnodes of a given type.

Args: node_type: The type of node to search for.

Returns: A list of all subnodes of the given type.

◆ get_setter_lambda()

Callable pytimeloop.timeloopfe.common.nodes copy.Node.get_setter_lambda ( self,
Union[str, int] keytag )

Get a function that can be used to set a value in this node.

The setter takes one argument, the value to set.

Args: keytag: The key or tag to set.

Returns: A function that can be used to set a value in this node.

◆ get_setters_for_keytag()

List[Tuple[Any, Callable]] pytimeloop.timeloopfe.common.nodes copy.Node.get_setters_for_keytag ( self,
str keytag,
bool recursive = True )

Get a list of tuples of the form (value, setter) for all keys/tags in this node that match the given key/tag.

A setter is a function that can be used to set a value in this node.

Args: keytag: The key or tag to search for. recursive: If True, search recursively.

◆ get_setters_for_type()

List[Tuple[Any, Callable]] pytimeloop.timeloopfe.common.nodes copy.Node.get_setters_for_type ( self,
Type t,
bool recursive = True )

Get a list of tuples of the form (value, setter) for all keys/tags in this node that match the given type.

A setter is a function that can be used to set a value in this node.

Args: t: The type to search for. recursive: If True, search recursively.

Returns: A list of tuples of the form (value, setter) for all keys/tags in this node that match the given type.

◆ get_specifiers_from_processors()

pytimeloop.timeloopfe.common.nodes copy.Node.get_specifiers_from_processors ( cls,
"BaseSpecification" spec )

Get the specifiers that have been set from processors.

◆ get_tag()

str pytimeloop.timeloopfe.common.nodes copy.Node.get_tag ( self)

Get the tag of this node.

◆ is_defined_non_default_non_empty()

bool pytimeloop.timeloopfe.common.nodes copy.Node.is_defined_non_default_non_empty ( self,
str key )

Returns True if the given key is defined in this node and is not the default value and is not empty.

◆ isempty()

bool pytimeloop.timeloopfe.common.nodes copy.Node.isempty ( self)

Return True if this node is empty.

Good to override.

◆ isempty_recursive()

bool pytimeloop.timeloopfe.common.nodes copy.Node.isempty_recursive ( self)

Return True if this node or all subnodes are empty.

◆ items()

Iterable[Tuple[Union[str, int], Any]] pytimeloop.timeloopfe.common.nodes copy.Node.items ( self)

Get iterable of (key, value) or (index, value) pairs.

◆ parse_expressions()

pytimeloop.timeloopfe.common.nodes copy.Node.parse_expressions ( self,
Optional[Dict[str, Any]] symbol_table = None,
Optional[set] parsed_ids = None,
Optional[Callable] callfunc = None )

Parse expressions in this node and all subnodes.

Args: symbol_table: A dictionary mapping variable names to values. parsed_ids: A set of IDs of nodes that have already been parsed. callfunc: A function to call on each node after parsing.

◆ recognize_all()

pytimeloop.timeloopfe.common.nodes copy.Node.recognize_all ( cls,
bool recognize_all = True )

Set whether all attributes under this node should be recognized.

Attributes: recognize_all (bool): Flag indicating whether all attributes under this node should be recognized.

◆ recursive_apply()

Any pytimeloop.timeloopfe.common.nodes copy.Node.recursive_apply ( self,
callable func,
bool self_first = False,
set applied_to = None )

Apply a function to this node and all subnodes.

Args: func (callable): The function to apply. self_first (bool): Flag indicating whether to apply the function to this node before applying it to subnodes. applied_to (set): A set of ids of nodes that have already been visited. Prevents infinite recursion.

Returns: The return value of the function applied to this node.

◆ reset_processor_elems()

pytimeloop.timeloopfe.common.nodes copy.Node.reset_processor_elems ( cls,
Optional[Type] processor = None )

◆ reset_specifiers_from_processors()

pytimeloop.timeloopfe.common.nodes copy.Node.reset_specifiers_from_processors ( cls,
Optional[Type] processor = None )

Reset the specifiers that have been set from processors.

◆ set_global_spec()

pytimeloop.timeloopfe.common.nodes copy.Node.set_global_spec ( "BaseSpecification" spec)
static

Set the global specification object.

◆ try_combine()

Any pytimeloop.timeloopfe.common.nodes copy.Node.try_combine ( Any a,
Any b,
Union["Node", None] innonde = None,
Union[int, str, None] index = None )
static

Try to combine two values.

Args: a: The first value. b: The second value. innonde: The node that contains the values. For error messages. index: The index of the values in the node. For error messages.

Returns: The combined value.

◆ unique_class_name()

pytimeloop.timeloopfe.common.nodes copy.Node.unique_class_name ( cls)

Return a unique name for this class.

Member Data Documentation

◆ __currently_parsing_index

pytimeloop.timeloopfe.common.nodes copy.Node.__currently_parsing_index = None
private

◆ _default_parse

bool pytimeloop.timeloopfe.common.nodes copy.Node._default_parse = False
protected

◆ _init_args

tuple pytimeloop.timeloopfe.common.nodes copy.Node._init_args = (args, kwargs)
protected

◆ logger

pytimeloop.timeloopfe.common.nodes copy.Node.logger = logging.getLogger(self.__class__.__name__)

◆ parent_node

Node pytimeloop.timeloopfe.common.nodes copy.Node.parent_node = None

◆ spec

BaseSpecification pytimeloop.timeloopfe.common.nodes copy.Node.spec = Node.get_global_spec()

The documentation for this class was generated from the following file: