Python's super(), abstract base classes, and NotImplementedError

前端 未结 3 1615
慢半拍i
慢半拍i 2021-02-03 14:45

Abstract base classes can still be handy in Python. In writing an abstract base class where I want every subclass to have, say, a spam() method, I want to write som

3条回答
  •  -上瘾入骨i
    2021-02-03 15:18

    Do not write all that code. Simple inspection of the abstract class can save you writing all that code.

    If the method is abstract, the concrete subclass does not call super.

    If the method is concrete, the concrete subclass does call super.

提交回复
热议问题