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 95 of file backends.py.

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

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 112 of file backends.py.

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

Member Data Documentation

◆ args

args = args

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

Definition at line 107 of file backends.py.

◆ generator_function

generator_function = generator_function

Generator function that has not been 'primed'.

Definition at line 105 of file backends.py.

◆ kwargs

kwargs = kwargs

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

Definition at line 109 of file backends.py.


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