Remove and return value for key with optional default.
(self, key, *args)
| 49 | break |
| 50 | |
| 51 | def pop(self, key, *args): |
| 52 | """Remove and return value for key with optional default.""" |
| 53 | if len(args) > 1: |
| 54 | raise TypeError( |
| 55 | f"pop expected at most 2 arguments, got {len(args) + 1}" |
| 56 | ) |
| 57 | try: |
| 58 | value = self[key] |
| 59 | del self[key] |
| 60 | return value |
| 61 | except KeyError: |
| 62 | if args: |
| 63 | return args[0] |
| 64 | raise |
| 65 | |
| 66 | def popitem(self): |
| 67 | """Remove and return an arbitrary (key, value) pair.""" |
no outgoing calls