1764a1765,1805 > .. _customizing-isinstance-issubclass > > Customizing instance and subclass checks > ---------------------------------------- > > .. versionadded:: 2.6 > > The following methods are used to override the default behavior of the > :func:`isinstance` and :func:`issubclass` built-in functions for instances > (normally, classes) of the classes (normally, metaclasses) implementing them. > > In particular, the metaclass :class:`abc.ABCMeta` implements these methods in > order to allow the addition of Abstract Base Classes (ABCs) as "virtual base > classes" to any class or type (including built-in types), and including to > other ABCs. > > > .. method:: object.__instancecheck__(self, instance) > > Return true if ``instance`` should be considered an instance of ``object``. > If defined, called to implement ``isinstance(instance, classinfo)`` when > ``object`` is, or is part of, ``classinfo``. > > > .. method:: object.__subclasscheck__(self, class) > > Return true if ``class`` should be considered a subclass of ``object``. > If defined, called to implement ``issubclass(class, classinfo)`` when > ``object`` is, or is part of, ``classinfo``. > > > .. seealso:: > > :pep:`3119` - Introducing Abstract Base Classes > Includes the specification for overloading :func:`isinstance` and > :func:`issubclass` through :meth:`__instancecheck__` and > :meth:`__subclasscheck__`, with motivation for this functionality in the > context of adding Abstract Base Classes (see the :mod:`abc` module) to > the language. > >