Serializes a given function or string. If 'keep_callable' is True, the original callable is returned. Otherwise, attempts to return the source code of the callable using 'getsource'.
(
self, value: Union[Callable, str], keep_callable=False
)
| 146 | return cfg_dict |
| 147 | |
| 148 | def serialize_function( |
| 149 | self, value: Union[Callable, str], keep_callable=False |
| 150 | ) -> Union[Callable, str]: |
| 151 | """Serializes a given function or string. |
| 152 | |
| 153 | If 'keep_callable' is True, the original callable is returned. |
| 154 | Otherwise, attempts to return the source code of the callable using 'getsource'. |
| 155 | """ |
| 156 | if keep_callable: |
| 157 | return value |
| 158 | else: |
| 159 | try: |
| 160 | return getsource(value) |
| 161 | except (TypeError, OSError): |
| 162 | return str(value) |
| 163 | |
| 164 | |
| 165 | class Task(abc.ABC): |