Return the function implementation for the given ``cls``
(self, cls)
| 742 | return wrapper(func) if func is not None else wrapper |
| 743 | |
| 744 | def dispatch(self, cls): |
| 745 | """Return the function implementation for the given ``cls``""" |
| 746 | lk = self._lookup |
| 747 | if cls in lk: |
| 748 | return lk[cls] |
| 749 | for cls2 in cls.__mro__: |
| 750 | # Is a lazy registration function present? |
| 751 | try: |
| 752 | toplevel, _, _ = cls2.__module__.partition(".") |
| 753 | except Exception: |
| 754 | continue |
| 755 | try: |
| 756 | register = self._lazy[toplevel] |
| 757 | except KeyError: |
| 758 | pass |
| 759 | else: |
| 760 | register() |
| 761 | self._lazy.pop(toplevel, None) |
| 762 | meth = self.dispatch(cls) # recurse |
| 763 | lk[cls] = meth |
| 764 | lk[cls2] = meth |
| 765 | return meth |
| 766 | try: |
| 767 | impl = lk[cls2] |
| 768 | except KeyError: |
| 769 | pass |
| 770 | else: |
| 771 | if cls is not cls2: |
| 772 | # Cache lookup |
| 773 | lk[cls] = impl |
| 774 | return impl |
| 775 | raise TypeError(f"No dispatch for {cls}") |
| 776 | |
| 777 | def __call__(self, arg, *args, **kwargs): |
| 778 | """ |