Get PyCharm to know what classes are mixin for

后端 未结 2 1441
遇见更好的自我
遇见更好的自我 2021-02-20 09:46

Our application has set of complex form wizards. To avoid code duplication I created several mixins.

The problem is that PyCharm highlights mixin methods with Unre

2条回答
  •  清酒与你
    2021-02-20 10:05

    If you are creating Mixin, for, let's say ClassSub, which is subclass of ClassSuper, you can implement Mixins this way:

    class Mixin1(ClassSuper):
        pass
    
    
    class Mixin2(ClassSuper):
        pass
    

    and then use them like:

    class ClassSub(Mixin1, Mixin2):
        pass
    

    That way I use some mixins for models in Django. Also, django-extensions uses similar pattern (gives models that are actually mixins). Basically, this way you don't have to inherit ClassSuper, because it's "included" in every of your mixins.

    Most important - PyCharm works like a charm this way.

提交回复
热议问题