Look up the formatter for a given instance. Parameters ---------- obj : object instance Returns ------- f : callable The registered formatting callable for the type. Raises ------ KeyError if the type has
(self, obj)
| 372 | ) |
| 373 | |
| 374 | def lookup(self, obj): |
| 375 | """Look up the formatter for a given instance. |
| 376 | |
| 377 | Parameters |
| 378 | ---------- |
| 379 | obj : object instance |
| 380 | |
| 381 | Returns |
| 382 | ------- |
| 383 | f : callable |
| 384 | The registered formatting callable for the type. |
| 385 | |
| 386 | Raises |
| 387 | ------ |
| 388 | KeyError if the type has not been registered. |
| 389 | """ |
| 390 | # look for singleton first |
| 391 | obj_id = id(obj) |
| 392 | if obj_id in self.singleton_printers: |
| 393 | return self.singleton_printers[obj_id] |
| 394 | # then lookup by type |
| 395 | return self.lookup_by_type(_get_type(obj)) |
| 396 | |
| 397 | def lookup_by_type(self, typ): |
| 398 | """Look up the registered formatter for a type. |