When a dependency of a function is not available, create a dummy function which throws ImportError when used. Args: func (str): name of the function. dependency (str or list[str]): name(s) of the dependency. Returns: function: a function object
(func, dependency)
| 47 | |
| 48 | |
| 49 | def create_dummy_func(func, dependency): |
| 50 | """ |
| 51 | When a dependency of a function is not available, create a dummy function which throws ImportError when used. |
| 52 | |
| 53 | Args: |
| 54 | func (str): name of the function. |
| 55 | dependency (str or list[str]): name(s) of the dependency. |
| 56 | |
| 57 | Returns: |
| 58 | function: a function object |
| 59 | """ |
| 60 | assert not building_rtfd() |
| 61 | |
| 62 | if isinstance(dependency, (list, tuple)): |
| 63 | dependency = ','.join(dependency) |
| 64 | |
| 65 | def _dummy(*args, **kwargs): |
| 66 | raise ImportError("Cannot import '{}', therefore '{}' is not available".format(dependency, func)) |
| 67 | return _dummy |
| 68 | |
| 69 | |
| 70 | def building_rtfd(): |
no test coverage detected