Type hints associate a Python variable, parameter, or return value with an intended type. In DuckDB user-defined functions, annotations let DuckDB infer SQL parameter and return types. section 6.4
Annotating a string UDF
def remove_spaces(field: str) -> str:\n if field:\n return field.lstrip().rstrip()\n return field\n\ncon.create_function('remove_spaces', remove_spaces)\n\nDuckDB registers the function as accepting and returning VARCHAR, so SQL can call remove_spaces(Region). section 6.4
Use annotations as the first choice, then specify types explicitly when inference is unreliable.
- Annotations keep the Python definition concise and communicate the intended interface. section 6.4
- Explicit parameter and return types improve clarity and consistency when annotations are absent or third-party code provides no hints. section 6.4
















