Pop a formatter for the given type. Parameters ---------- typ : type or '__module__.__name__' string for a type default : object value to be returned if no formatter is registered for typ. Returns ------- obj : object
(self, typ, default=_raise_key_error)
| 507 | return oldfunc |
| 508 | |
| 509 | def pop(self, typ, default=_raise_key_error): |
| 510 | """Pop a formatter for the given type. |
| 511 | |
| 512 | Parameters |
| 513 | ---------- |
| 514 | typ : type or '__module__.__name__' string for a type |
| 515 | default : object |
| 516 | value to be returned if no formatter is registered for typ. |
| 517 | |
| 518 | Returns |
| 519 | ------- |
| 520 | obj : object |
| 521 | The last registered object for the type. |
| 522 | |
| 523 | Raises |
| 524 | ------ |
| 525 | KeyError if the type is not registered and default is not specified. |
| 526 | """ |
| 527 | |
| 528 | if isinstance(typ, str): |
| 529 | typ_key = tuple(typ.rsplit('.',1)) |
| 530 | if typ_key not in self.deferred_printers: |
| 531 | # We may have it cached in the type map. We will have to |
| 532 | # iterate over all of the types to check. |
| 533 | for cls in self.type_printers: |
| 534 | if _mod_name_key(cls) == typ_key: |
| 535 | old = self.type_printers.pop(cls) |
| 536 | break |
| 537 | else: |
| 538 | old = default |
| 539 | else: |
| 540 | old = self.deferred_printers.pop(typ_key) |
| 541 | else: |
| 542 | if typ in self.type_printers: |
| 543 | old = self.type_printers.pop(typ) |
| 544 | else: |
| 545 | old = self.deferred_printers.pop(_mod_name_key(typ), default) |
| 546 | if old is _raise_key_error: |
| 547 | raise KeyError("No registered value for {0!r}".format(typ)) |
| 548 | return old |
| 549 | |
| 550 | def _in_deferred_types(self, cls): |
| 551 | """ |