I am having trouble patching a custom class' __init_subclass__. I think it has to do with the way that I am binding the patched function to the class:
def _patched_initsubclass(cls, **kwargs):
print(f"CLS from subclassing A: {cls}")
super(cls, cls).__init_subclass__(**kwargs)
class A: ...
A.__init_subclass__ = _patched_initsubclass.__get__(A, A)
class B(A): ... # Output: CLS from subclassing A: <class '__main__.A'>
However, I know that a properly set __init_subclass__ should have a different output:
class F:
def __init_subclass__(cls, **kwargs):
print(f"CLS from subclassing F: {cls}")
pass
class C(F): ... # Output: CLS from subclassing F: <class '__main__.C'>
i.e. cls in the super class' __init_subclass__ definition should be the subclass when subclassed. I've tried to find the correct way to bind the dunder method through different SO posts plus the docs, but haven't been able to find the correct way to do it.