Pop an attribute, similar to dict's pop method Args: key: Name of the attribute to pop default: Default value to return if attribute does not exist Returns: Popped attribute value, or default if attribute doesn't exist and default is pro
(self, key, default=None)
| 44 | setattr(self, key, value) |
| 45 | |
| 46 | def pop(self, key, default=None): |
| 47 | """ |
| 48 | Pop an attribute, similar to dict's pop method |
| 49 | |
| 50 | Args: |
| 51 | key: Name of the attribute to pop |
| 52 | default: Default value to return if attribute does not exist |
| 53 | |
| 54 | Returns: |
| 55 | Popped attribute value, or default if attribute doesn't exist and default is provided |
| 56 | """ |
| 57 | if hasattr(self, key): |
| 58 | value = getattr(self, key) |
| 59 | delattr(self, key) |
| 60 | return value |
| 61 | elif default is not None: |
| 62 | return default |
| 63 | else: |
| 64 | raise KeyError(f"'{key}' is not a valid attribute of InputBatch") |
| 65 | |
| 66 | def __delitem__(self, key): |
| 67 | """ |
no outgoing calls