MCPcopy Index your code
hub / github.com/tensorpack/tensorpack / create_dummy_class

Function create_dummy_class

tensorpack/utils/develop.py:22–46  ·  view source on GitHub ↗

When a dependency of a class is not available, create a dummy class which throws ImportError when used. Args: klass (str): name of the class. dependency (str): name of the dependency. Returns: class: a class object

(klass, dependency)

Source from the content-addressed store, hash-verified

20
21
22def create_dummy_class(klass, dependency):
23 """
24 When a dependency of a class is not available, create a dummy class which throws ImportError when used.
25
26 Args:
27 klass (str): name of the class.
28 dependency (str): name of the dependency.
29
30 Returns:
31 class: a class object
32 """
33 assert not building_rtfd()
34
35 class _DummyMetaClass(type):
36 # throw error on class attribute access
37 def __getattr__(_, __):
38 raise AttributeError("Cannot import '{}', therefore '{}' is not available".format(dependency, klass))
39
40 @six.add_metaclass(_DummyMetaClass)
41 class _Dummy(object):
42 # throw error on constructor
43 def __init__(self, *args, **kwargs):
44 raise ImportError("Cannot import '{}', therefore '{}' is not available".format(dependency, klass))
45
46 return _Dummy
47
48
49def create_dummy_func(func, dependency):

Callers 9

graph.pyFile · 0.85
image.pyFile · 0.85
format.pyFile · 0.85
serialize.pyFile · 0.85
bsds500.pyFile · 0.85
svhn.pyFile · 0.85
ilsvrc.pyFile · 0.85
places.pyFile · 0.85
caltech101.pyFile · 0.85

Calls 1

building_rtfdFunction · 0.85

Tested by

no test coverage detected