MCPcopy Create free account
hub / github.com/open-mmlab/mmengine / pop

Method pop

mmengine/structures/base_data_element.py:425–443  ·  view source on GitHub ↗

Pop property in data and metainfo as the same as python.

(self, *args)

Source from the content-addressed store, hash-verified

423 return getattr(self, key, default)
424
425 def pop(self, *args) -> Any:
426 """Pop property in data and metainfo as the same as python."""
427 assert len(args) < 3, '``pop`` get more than 2 arguments'
428 name = args[0]
429 if name in self._metainfo_fields:
430 self._metainfo_fields.remove(args[0])
431 return self.__dict__.pop(*args)
432
433 elif name in self._data_fields:
434 self._data_fields.remove(args[0])
435 return self.__dict__.pop(*args)
436
437 # with default value
438 elif len(args) == 2:
439 return args[1]
440 else:
441 # don't just use 'self.__dict__.pop(*args)' for only popping key in
442 # metainfo or data
443 raise KeyError(f'{args[0]} is not contained in metainfo or data')
444
445 def __contains__(self, item: str) -> bool:
446 """Whether the item is in dataelement.

Callers 2

test_delete_modifyMethod · 0.95
_addindentMethod · 0.45

Calls 1

removeMethod · 0.45

Tested by 1

test_delete_modifyMethod · 0.76