MCPcopy Create free account
hub / github.com/DeepGraphLearning/graphvite / TemplateHelper

Class TemplateHelper

python/graphvite/helper.py:83–105  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

81
82
83class TemplateHelper(object):
84
85 def __new__(cls, *args, **kwargs):
86 args = list(args)
87 parameters = []
88 for i, key in enumerate(cls.template_keys):
89 if args:
90 parameters.append(args.pop(0))
91 elif key in kwargs:
92 parameters.append(kwargs.pop(key))
93 else:
94 value = cls.template_values[i]
95 if value is None:
96 raise TypeError("Required argument `%s` (pos %d) not found" % (key, i))
97 else:
98 parameters.append(value)
99
100 full_name = signature(cls.name, *parameters)
101 if hasattr(cls.module, full_name):
102 return getattr(cls.module, full_name)(*args, **kwargs)
103 else:
104 strings = ["%s=%s" % (k, v) for k, v in zip(cls.template_keys, parameters)]
105 raise AttributeError("Can't find an instantiation of %s with %s" % (cls.name, ", ".join(strings)))
106
107
108def make_helper_class(module, name, target_module, template_keys, template_values):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected