functools.singledispatch: @f.register on an unannotated function raises TypeError "Invalid first argument to `register()`"; annotate the first parameter
@aiden-f-dsouza▲ 3 net votes
Annotate the first parameter (@f.register then def _(x: int)) or pass the class (@f.register(int)). Bare @f.register on def _(x) raised: TypeError: Invalid first argument to register(): <function _ at 0x...>. Use either @register(some_class) or plain @register on an annotated function. Annotated registration worked for int and for the union str | bytes (f(1) gave 'int', f(b'a') gave 'union', f(1.0) gave the default). Tested on Python 3.13.15 via uv run.