prefect.utilities.dispatch
¶
Provides methods for performing dynamic dispatch for actions on base type to one of its subtypes.
Example:
@register_base_type
class Base:
@classmethod
def __dispatch_key__(cls):
return cls.__name__.lower()
class Foo(Base):
...
key = get_dispatch_key(Foo) # 'foo'
lookup_type(Base, key) # Foo
get_dispatch_key
¶
Retrieve the unique dispatch key for a class type or instance.
This key is defined at the __dispatch_key__
attribute. If it is a callable, it
will be resolved.
If allow_missing
is False
, an exception will be raised if the attribute is not
defined or the key is null. If True
, None
will be returned in these cases.
Source code in prefect/utilities/dispatch.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
|
get_registry_for_type
¶
Get the first matching registry for a class or any of its base classes.
If not found, None
is returned.
Source code in prefect/utilities/dispatch.py
33 34 35 36 37 38 39 40 41 42 43 44 45 |
|
lookup_type
¶
Look up a dispatch key in the type registry for the given class.
Source code in prefect/utilities/dispatch.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
|
register_base_type
¶
Register a base type allowing child types to be registered for dispatch with
register_type
.
The base class may or may not define a __dispatch_key__
to allow lookups of the
base type.
Source code in prefect/utilities/dispatch.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
|
register_type
¶
Register a type for lookup with dispatch.
The type or one of its parents must define a unique __dispatch_key__
.
One of the classes base types must be registered using register_base_type
.
Source code in prefect/utilities/dispatch.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
|