Pop property in data and metainfo as the same as python.
(self, *args)
| 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. |