# Make abc.ABC a regular class by making \_\_instancecheck\_\_ and \_\_subclasscheck\_\_ class methods

**URL:** <https://discuss.python.org/t/make-abc-abc-a-regular-class-by-making-instancecheck-and-subclasscheck-class-methods/47547>\
**Category:** Ideas\
**Created:** [March 4, 2024, 9:29am UTC](https://discuss.python.org/t/make-abc-abc-a-regular-class-by-making-instancecheck-and-subclasscheck-class-methods/47547 "2024-03-04T09:29:02Z")\
**Posts on this page:** 1\
**Showing post:** 45

<div class="post-metadata">

**Author:** ![blhsing](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/blhsing/32/25812_2.png) [@blhsing](https://discuss.python.org/u/blhsing)\
**Post date:** [March 5, 2024, 12:14am UTC](https://discuss.python.org/t/make-abc-abc-a-regular-class-by-making-instancecheck-and-subclasscheck-class-methods/47547/45 "2024-03-05T00:14:33Z")

</div>

> [@mikeshardmind](#):
>
> I generally think the ABC method is worse than using protocols (runtime checkable ones, even, if needed), but ABC came first, and comes with runtime enforcement that subclasses implemented the abstract methods.

`ABC` and `Protocol` serve entirely different use cases. `ABC` enforces structure of a subclass, while `Protocol` enforces structure of an instance. Moreover, `ABC` implements actual logical behaviors while `Protocol` does none.

I think my recent use case of `ABC` demonstrates its purpose well:

> [@Context manager protocol extension (2nd attempt)](https://discuss.python.org/t/context-manager-protocol-extension-2nd-attempt/44888/42):
>
> Note that we can make it a mixin class too for easier usage: from abc import ABC, abstractmethod from contextlib import contextmanager class ContextManagerMixin(ABC): def \_\_init\_\_(self): self.\_contexts = [] def \_\_init\_subclass\_\_(cls): cls.\_\_with\_\_ = contextmanager(cls.\_\_with\_\_) @abstractmethod def \_\_with\_\_(self): ... def \_\_enter\_\_(self): context = self.\_\_with\_\_() self.\_contexts.append(context) return context.\_\_enter\_\_() def \_\_…

But now imagine how someone who wishes to use this mixin class to easily gain this small capability of a context manager, only to end up with a metaclass conflict with a big metaclass-based base class that actually legitimately needs a metaclass, all because of ` __instancecheck__ ` and ` __subclasscheck__ ` that aren’t even used.

---

_[View the full topic](https://discuss.python.org/t/make-abc-abc-a-regular-class-by-making-instancecheck-and-subclasscheck-class-methods/47547)._
