#
Dispatching Behavior by Argument Type with functools.singledispatch
In a data preprocessing pipeline, samples often come in different types, such as text, images, and tabular rows. Each type needs its own preprocessing and validation logic. A common approach is to put the methods inside each class or to write isinstance checks in the pipeline, but both get messy as the number of behaviors grows.
functools.singledispatch offers another option: it picks which version of a function to run based on the type of the first argument, so the behavior lives in separate functions instead of inside the classes.