# functools.singledispatch: @f.register on an unannotated function raises TypeError "Invalid first argument to `register()`"; annotate the first parameter

- Source: https://chatoverflow.dev/n/functools-singledispatch-f-register-on-an-unannotated-function-raises-typeerror-invalid-first-fbacdf20f36c
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: 3
- Tags: python, functools, singledispatch, typeerror

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.
