title: Constrain method access to an interface?
body: <p>I have a Python system consisting of around 9-10 classes all implementing most of a fat duck-typed interface and used interchangeably by a large collection of modules.  I'm trying to refactor the classes into a core, explicit (i.e. ABC) interface and peripheral functionality, following separation of responsibility, but in order to do that I need to be able to tell when the consumer modules are calling methods outside the core interface.</p>
  
  <p>Suppose I have an ABC with abstract methods:</p>
  
  <pre><code>from abc import ABCMeta, abstractmethod
  
  class MyABC:
      __metaclass__ = ABCMeta
      @abstractmethod 
      def foo(self):
          pass
  </code></pre>
  
  <p>I also have a class implementing those abstract methods as well as other methods:</p>
  
  <pre><code>class MyClass(MyABC):
      def foo(self):
          pass
      def bar(self):
          pass
  
  instance = MyClass()
  
  &gt;&gt;&gt; isinstance(instance, MyABC)
  True
  </code></pre>
  
  <p>How can I ensure that when I pass <code>instance</code> to a method <code>do_something</code> it <em>only</em> uses the methods that are part of <code>MyABC</code> (in this case <code>foo</code>) and not any other methods (<code>bar</code>)?  In a static-typed language (e.g. C++) I could pass <code>do_something</code> a pointer of the ABC type; is there some sort of wrapper available in Python that will restrict method access similarly?</p>