Belle II Software development
ArgumentsGenerator Class Reference

Public Member Functions

 __init__ (self, generator_function, *args, **kwargs)
 
 generator (self)
 

Public Attributes

 generator_function = generator_function
 Generator function that has not been 'primed'.
 
 args = args
 Positional argument tuple used to 'prime' the ArgumentsGenerator.generator_function.
 
 kwargs = kwargs
 Keyword argument dictionary used to 'prime' the ArgumentsGenerator.generator_function.
 

Detailed Description

Simple little class to hold a generator (uninitialised) and the necessary args/kwargs to
initialise it. This lets us reuse a generator by setting it up again fresh. This is not
optimal for expensive calculations, but it is nice for making large sequences of
Job input arguments on the fly.

Definition at line 87 of file backends.py.

Constructor & Destructor Documentation

◆ __init__()

__init__ ( self,
generator_function,
* args,
** kwargs )
Parameters:
    generator_function (py:function): A function (callable) that contains a ``yield`` statement. This generator
        should *not* be initialised i.e. you haven't called it with ``generator_function(*args, **kwargs)``
        yet. That will happen when accessing the `ArgumentsGenerator.generator` property.
    args (tuple): The positional arguments you want to send into the initialisation of the generator.
    kwargs (dict): The keyword arguments you want to send into the initialisation of the generator.

Definition at line 94 of file backends.py.

94 def __init__(self, generator_function, *args, **kwargs):
95 """
96 Parameters:
97 generator_function (py:function): A function (callable) that contains a ``yield`` statement. This generator
98 should *not* be initialised i.e. you haven't called it with ``generator_function(*args, **kwargs)``
99 yet. That will happen when accessing the `ArgumentsGenerator.generator` property.
100 args (tuple): The positional arguments you want to send into the initialisation of the generator.
101 kwargs (dict): The keyword arguments you want to send into the initialisation of the generator.
102 """
103
104 self.generator_function = generator_function
105
106 self.args = args
107
108 self.kwargs = kwargs
109

Member Function Documentation

◆ generator()

generator ( self)
Returns:
    generator: The initialised generator (using the args and kwargs for initialisation). It should be ready
    to have ``next``/``send`` called on it.

Definition at line 111 of file backends.py.

111 def generator(self):
112 """
113 Returns:
114 generator: The initialised generator (using the args and kwargs for initialisation). It should be ready
115 to have ``next``/``send`` called on it.
116 """
117 gen = self.generator_function(*self.args, **self.kwargs)
118 gen.send(None) # Prime it
119 return gen
120
121

Member Data Documentation

◆ args

args = args

Positional argument tuple used to 'prime' the ArgumentsGenerator.generator_function.

Definition at line 106 of file backends.py.

◆ generator_function

generator_function = generator_function

Generator function that has not been 'primed'.

Definition at line 104 of file backends.py.

◆ kwargs

kwargs = kwargs

Keyword argument dictionary used to 'prime' the ArgumentsGenerator.generator_function.

Definition at line 108 of file backends.py.


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