issubclass() is a built-in Python function that checks whether one class is a subclass (direct or indirect) of another class — returning True if the first class inherits from the second (or any class in a tuple of classes), and False otherwise. Unlike isinstance() (for instances), issubclass() works purely at the class level and supports inheritance chains and tuple checks. In 2026, issubclass() remains a core tool in data science (type hierarchy validation in pandas/Polars/Dask extensions), software engineering (plugin compatibility, protocol checks), and modern Python (typing.Protocol, ABCs, structural subtyping) — enabling safe, inheritance-aware type checking without creating instances.
Here’s a complete, practical guide to using issubclass() in Python: basic subclass checks, tuple of base classes, real-world patterns (earthquake model validation, plugin system compatibility), and modern best practices with type hints, performance, abstract base classes, and integration with Dask/Polars/pandas/dataclasses/typing/abc.
Basic issubclass() — check single base class or tuple of bases.
class Shape: pass
class Rectangle(Shape): pass
class Square(Rectangle): pass
class Circle(Shape): pass
print(issubclass(Rectangle, Shape)) # True
print(issubclass(Square, Rectangle)) # True
print(issubclass(Square, Shape)) # True (indirect inheritance)
print(issubclass(Circle, Rectangle)) # False
# Tuple check (OR logic)
print(issubclass(Square, (Rectangle, Circle))) # True
print(issubclass(Circle, (Rectangle, Square))) # False
Real-world pattern: validating inheritance in earthquake data model hierarchy.
from abc import ABC, abstractmethod
class QuakeEvent(ABC):
@abstractmethod
def magnitude(self) -> float:
pass
class USGSQuake(QuakeEvent):
def magnitude(self) -> float:
return 7.2
class CustomQuake(QuakeEvent):
def magnitude(self) -> float:
return 6.8
class NonEvent:
def magnitude(self) -> float:
return 5.0
events = [USGSQuake(), CustomQuake(), NonEvent()]
# Filter only valid QuakeEvent subclasses
valid_events = [
event for event in events
if issubclass(event.__class__, QuakeEvent)
]
print(f"Valid quake events: {len(valid_events)}") # 2
# Check if class supports required interface
def is_quake_class(cls):
return issubclass(cls, QuakeEvent)
print(is_quake_class(USGSQuake)) # True
print(is_quake_class(NonEvent)) # False
Advanced usage — ABCs, Protocol, multiple inheritance, and dynamic checks.
from typing import Protocol
class HasMag(Protocol):
mag: float
class MagEvent:
mag = 7.5
class NoMagEvent:
pass
print(issubclass(MagEvent.__class__, HasMag)) # False (Protocol not in MRO)
# Note: issubclass() does NOT work with Protocol for structural checks
# Use typing.TypeGuard or runtime check instead
# Multiple inheritance
class A: pass
class B: pass
class C(A, B): pass
print(issubclass(C, A)) # True
print(issubclass(C, B)) # True
print(issubclass(C, (A, B))) # True
Best practices for issubclass() in Python & data workflows. Prefer issubclass(cls, Base) — over type(cls) is Base (handles inheritance). Modern tip: use Polars/Dask — issubclass(type(df), (pd.DataFrame, dd.DataFrame)) for multi-backend code. Use tuple for OR checks — issubclass(cls, (Base1, Base2)). Add type hints — def is_event_class(cls: type) -> bool. Use issubclass() in factories — validate subclass before instantiation. Use issubclass() with ABCs — enforce interface compliance. Use issubclass() in metaclasses — dynamic class validation. Use issubclass(cls, ABC) — check abstract base class compliance. Avoid issubclass() with Protocol — use runtime isinstance() or TypeGuard instead. Use issubclass(cls, tuple) — for tuple subclasses. Use issubclass(cls, (int, float)) — numeric type check. Use issubclass(type(obj), Class) — for instance type check (equivalent to isinstance(obj, Class)). Profile performance — issubclass() is fast; avoid in ultra-tight loops. Use inspect.isclass(obj) — check if object is class before issubclass. Use inspect.getmro(cls) — full method resolution order. Use cls.mro() — same as getmro. Use issubclass(cls, Exception) — check exception subclasses.
issubclass(cls, classinfo) checks if a class is a subclass of another class or tuple of classes — handles direct/indirect inheritance, supports ABCs and multiple bases. In 2026, use for type validation, plugin compatibility, interface enforcement, and dynamic dispatch in Dask/Polars/pandas extensions. Master issubclass(), and you’ll write inheritance-aware, robust, and extensible code in any Python project.
Next time you need to verify class inheritance — use issubclass(). It’s Python’s cleanest way to say: “Is this class a subclass of that — including indirect inheritance?”