title: How can I create a Protocol that encompases both threading.Event and multiprocessing.Event?
body: <p>In the Python standard library <code>multiprocessing.Event</code> is explicitly stated to be a clone of <code>threading.Event</code> and to have the same interface.  I would like to annotate variables and arguments so that they can accept either of those classes, and <code>mypy</code> would type-check them.  I tried creating a Protocol (I used <code>multiprocessing.synchronize.Event</code> since that is the actual class that is returned by <code>multiprocessing.Event</code>).</p>
  
  <pre class="lang-py prettyprint-override"><code>import multiprocessing
  import threading
  
  from typing import Optional, Type, Protocol
  
  
  class Event(Protocol):
      def wait(self, timeout: Optional[float]) -&gt; bool:
          ...
  
      def set(self) -&gt; None:
          ...
  
      def clear(self) -&gt; None:
          ...
  
      def is_set(self) -&gt; bool:
          ...
  
  
  class Base:
      flag_class: Type[Event]
  
      def foo(self, e: Event):
          pass
  
  
  class DerivedOne(Base):
      flag_class = multiprocessing.synchronize.Event
  
      def foo(self, e: multiprocessing.synchronize.Event):
          pass
  
  
  class DerivedTwo(Base):
      flag_class = threading.Event
  
      def foo(self, e: threading.Event):
          pass
  </code></pre>
  
  <p>However, <code>mypy</code> (version 0.761) doesn't recognize that <code>multiprocessing.Event</code> and <code>threading.Event</code> both implement the protocol I defined:</p>
  
  <pre class="lang-sh prettyprint-override"><code>$ mypy proto.py
  
  proto.py:31: error: Argument 1 of "foo" is incompatible with supertype "Base"; supertype defines the argument type as "Event"
  proto.py:38: error: Argument 1 of "foo" is incompatible with supertype "Base"; supertype defines the argument type as "Event"
  Found 2 errors in 1 file (checked 1 source file)
  </code></pre>
  
  <p>Why doesn't <code>mypy</code> recognize my protocol and how can I fix it?</p>