title: How to incorporate type checking in an abstract base class in Python
body: <p>When I define a class, I like to include type checking (using <code>assert</code>) of the input variables. I am now defining a 'specialized' class <code>Rule</code> which inherits from an abstract base class (ABC) <code>BaseRule</code>, similar to the following:</p>
  
  <pre><code>import abc
  
  class BaseRule(object):
      __metaclass__ = abc.ABCMeta
  
      @abc.abstractproperty
      def resources(self):
          pass
  
  
  class Rule(BaseRule):
      def __init__(self, resources):
          assert all(isinstance(resource, Resource) for resource in resources)    # type checking
          self._resources = resources
  
      @property
      def resources(self):
          return self._resources
  
  
  class Resource(object):
      def __init__(self, domain):
          self.domain = domain
  
  
  if __name__ == "__main__":
      resources = [Resource("facebook.com")]
      rule = Rule(resources)
  </code></pre>
  
  <p>The <code>assert</code> statement in the <code>__init__</code> function of the <code>Rule</code> class ensures that the <code>resources</code> input is a list (or other iterable) of <code>Resource</code> objects. However, this would also be the case for other classes which inherit from <code>BaseRule</code>, so I would like to incorporate this assertion in the <code>abstractproperty</code> somehow. How might I go about this?</p>