Class Decorators, Inheritance, super(), and maximum recursion

前端 未结 5 1813
故里飘歌
故里飘歌 2020-12-31 19:52

I\'m trying to figure out how to use decorators on subclasses that use super(). Since my class decorator creates another subclass a decorated class seems to pre

5条回答
  •  无人及你
    2020-12-31 20:37

    The decorator creates a kind-of diamond inheritance situation. You can avoid these problems by not using super(). Changing SubClassAgain to the following will prevent infinite recursion:

    @class_decorator
    class SubClassAgain(BaseClass):
        def print_class(self):
            BaseClass.print_class(self)
    

提交回复
热议问题