user329841
0
Q:

python __init_subclass__

In [16]: class Foo:
    ...:     def __init_subclass__(cls):
    ...:         print('ok')
    ...:         print(cls.att)

In [17]: class SubFoo(Foo):
    ...:     att = 1
    ...:     pass
    ...:
ok
1

# So: __init_subclass__ runs everytime that Foo is subclassed.
# Also: the argument `cls` of __init_subclass__ is the subclass.
1

New to Communities?

Join the community