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

Function _default_repr

tensorpack/dataflow/imgaug/base.py:28–61  ·  view source on GitHub ↗

Produce something like: "imgaug.MyAugmentor(field1={self.field1}, field2={self.field2})" It assumes that the instance `self` contains attributes that match its constructor.

(self)

Source from the content-addressed store, hash-verified

26
27
28def _default_repr(self):
29 """
30 Produce something like:
31 "imgaug.MyAugmentor(field1={self.field1}, field2={self.field2})"
32
33 It assumes that the instance `self` contains attributes that match its constructor.
34 """
35 classname = type(self).__name__
36 argspec = inspect.getfullargspec(self.__init__)
37 assert argspec.varargs is None, "The default __repr__ in {} doesn't work for varargs!".format(classname)
38 assert argspec.varkw is None, "The default __repr__ in {} doesn't work for kwargs!".format(classname)
39 defaults = {}
40
41 fields = argspec.args[1:]
42 defaults_pos = argspec.defaults
43 if defaults_pos is not None:
44 for f, d in zip(fields[::-1], defaults_pos[::-1]):
45 defaults[f] = d
46
47 for k in argspec.kwonlyargs:
48 fields.append(k)
49 if k in argspec.kwonlydefaults:
50 defaults[k] = argspec.kwonlydefaults[k]
51
52 argstr = []
53 for f in fields:
54 assert hasattr(self, f), \
55 "Attribute {} in {} not found! Default __repr__ only works if " \
56 "the instance has attributes that match the constructor.".format(f, classname)
57 attr = getattr(self, f)
58 if f in defaults and attr is defaults[f]:
59 continue
60 argstr.append("{}={}".format(f, pprint.pformat(attr)))
61 return "imgaug.{}({})".format(classname, ', '.join(argstr))
62
63
64ImagePlaceholder = namedtuple("ImagePlaceholder", ["shape"])

Callers 2

__str__Method · 0.85
__repr__Method · 0.85

Calls 3

formatMethod · 0.80
appendMethod · 0.80
joinMethod · 0.80

Tested by

no test coverage detected