title: Python determine if class is abstract (ABC) without abstractmethod
body: <p>I have a class that inherits from <a href="https://docs.python.org/3/library/abc.html#abc.ABC" rel="nofollow noreferrer"><code>ABC</code></a>, and does not have any <code>abstractmethod</code>.</p>
  
  <p>I would like to check if it's an abstract class, and am currently stumped.</p>
  
  <p><a href="https://stackoverflow.com/questions/14410860/determine-if-a-python-class-is-an-abstract-base-class-or-concrete">Determine if a Python class is an Abstract Base Class or Concrete</a> prescribes using <code>inspect.isabstract</code>.  However, this only works if an <code>abstractmethod</code> has been used.</p>
  
  <p>How can I detect if a class inherits directly from <code>ABC</code>, without using <code>inspect.isabstract</code>?</p>
  
  <hr>
  
  <p><strong>Test Cases</strong></p>
  
  <pre class="lang-py prettyprint-override"><code># I need this to be flagged as abstract
  class AbstractBaseClassNoAbsMethod(ABC):
      pass
  
  
  # This is currently flaggable with `inspect.isabstract`
  class AbstractBaseClassWithAbsMethod(ABC):
      @abstractmethod
      def some_method(self):
          """Abstract method."""
  
  
  # I need this to be flagged as not abstract
  class ChildClassFromNoAbsMethod(AbstractBaseClassNoAbsMethod):
      pass
  </code></pre>
  
  <p>I considered using <code>issubclass(some_class, ABC)</code>, but this is <code>True</code>, even for the above <code>ChildClassFromNoAbsMethod</code>.</p>
  
  <hr>
  
  <p><strong>Current Best Solution</strong></p>
  
  <p>My current best solution works using <code>__bases__</code>.  This is basically just listing parent classes, see <a href="https://stackoverflow.com/questions/2611892/how-to-get-the-parents-of-a-python-class">How to get the parents of a Python class?</a></p>
  
  <pre class="lang-py prettyprint-override"><code>def my_isabstract(obj) -&gt; bool:
      """Get if ABC is in the object's __bases__ attribute."""
      try:
          return ABC in obj.__bases__
      except AttributeError:
          return False
  </code></pre>
  
  <p>This is a viable solution.  I am not sure if there is a better/more standard way out there.</p>