Force implementation of class methods

If you want to make sure that a Subclass implements certain methods of it's parent in Python, you can do this:


import pytest
from abc import ABCMeta, abstractmethod

class AbstractSubject(object):
    """A common interface for the real and proxy objects."""

    __metaclass__ = ABCMeta

    def sort(self, reverse=False):

class RealSubject(AbstractSubject):

with pytest.raises(TypeError):
    real_subject1 = RealSubject()

When RealSubject doesn't have the sort method implemented, it will throw an error on initialization of RealSubject.