MCPcopy Create free account
hub / github.com/OpenGVLab/HumanBench / __repr__

Method __repr__

PATH/core/data/transforms/seg_transforms_dev.py:217–248  ·  view source on GitHub ↗

Produce something like: "MyTransform(field1={self.field1}, field2={self.field2})"

(self)

Source from the content-addressed store, hash-verified

215 raise NotImplementedError
216
217 def __repr__(self):
218 """
219 Produce something like:
220 "MyTransform(field1={self.field1}, field2={self.field2})"
221 """
222 try:
223 sig = inspect.signature(self.__init__)
224 classname = type(self).__name__
225 argstr = []
226 for name, param in sig.parameters.items():
227 assert (
228 param.kind != param.VAR_POSITIONAL
229 and param.kind != param.VAR_KEYWORD
230 ), "The default __repr__ doesn't support *args or **kwargs"
231 assert hasattr(self, name), (
232 "Attribute {} not found! "
233 "Default __repr__ only works if attributes match the constructor.".format(
234 name
235 )
236 )
237 attr = getattr(self, name)
238 default = param.default
239 if default is attr:
240 continue
241 attr_str = pprint.pformat(attr)
242 if "\n" in attr_str:
243 # don't show it if pformat decides to use >1 lines
244 attr_str = "..."
245 argstr.append("{}={}".format(name, attr_str))
246 return "{}({})".format(classname, ", ".join(argstr))
247 except AssertionError:
248 return super().__repr__()
249
250
251_T = TypeVar("_T")

Callers 1

__repr__Method · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected