August 2018
Intermediate to advanced
366 pages
10h 14m
English
The function decorated with @singledispatch actually gets replaced by a check for the argument type.
Each call to human_readable.register will record into a registry which callable should be used for each argument type:
>>> human_readable.registry
mappingproxy({
<class 'list'>: <function human_readable_list at 0x10464da60>,
<class 'object'>: <function human_readable at 0x10464d6a8>,
<class 'dict'>: <function human_readable_dict at 0x10464d950>,
<class 'tuple'>: <function human_readable_list at 0x10464da60>
})
Whenever the decorated function gets called, it will instead look up the type of the argument in the registry and will forward the call to the associated function for execution.
The function decorated with @singledispatch ...