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)
| 571 | return oldfunc |
| 572 | |
| 573 | def pop(self, typ, default=_raise_key_error): |
| 574 | """Pop a formatter for the given type. |
| 575 | |
| 576 | Parameters |
| 577 | ---------- |
| 578 | typ : type or '__module__.__name__' string for a type |
| 579 | default : object |
| 580 | value to be returned if no formatter is registered for typ. |
| 581 | |
| 582 | Returns |
| 583 | ------- |
| 584 | obj : object |
| 585 | The last registered object for the type. |
| 586 | |
| 587 | Raises |
| 588 | ------ |
| 589 | KeyError if the type is not registered and default is not specified. |
| 590 | """ |
| 591 | |
| 592 | if isinstance(typ, str): |
| 593 | typ_key = tuple(typ.rsplit('.',1)) |
| 594 | if typ_key not in self.deferred_printers: |
| 595 | # We may have it cached in the type map. We will have to |
| 596 | # iterate over all of the types to check. |
| 597 | for cls in self.type_printers: |
| 598 | if _mod_name_key(cls) == typ_key: |
| 599 | old = self.type_printers.pop(cls) |
| 600 | break |
| 601 | else: |
| 602 | old = default |
| 603 | else: |
| 604 | old = self.deferred_printers.pop(typ_key) |
| 605 | else: |
| 606 | if typ in self.type_printers: |
| 607 | old = self.type_printers.pop(typ) |
| 608 | else: |
| 609 | old = self.deferred_printers.pop(_mod_name_key(typ), default) |
| 610 | if old is _raise_key_error: |
| 611 | raise KeyError("No registered value for {0!r}".format(typ)) |
| 612 | return old |
| 613 | |
| 614 | def _in_deferred_types(self, cls): |
| 615 | """ |