This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def hook_type(to_hook, new_cls: type): | |
| if to_hook not in new_cls.__mro__: | |
| raise TypeError(f"{new_cls} musst subclass {to_hook}") | |
| old_new = to_hook.__new__ | |
| def hook(_, *args, **kwargs) -> type: | |
| if hasattr(old_new, "__self__"): | |
| if old_new.__self__ is object: | |
| return old_new(new_cls) | |
| return old_new(new_cls, *args, **kwargs) |