Python Abstract Classes

Author

Simone Massaro

Published

March 26, 2026

Today I learned that python has abstract classes. You can do something like:

from abc import ABC, abstractmethod

class Hittable(ABC):
    @abstractmethod
    def hit(self, ray_tmin: float, ray_tmax: float, rec: HitRecord) -> bool: ...

This is like having a virtual method in C++ and the base class is also not directly instantiable.