Skip to main content

get_click_type

Determines and returns the appropriate click.ParamType based on a provided type annotation and parameter metadata. It maps standard Python types, Enums, and Literals to Click-compatible types, including support for ranges, files, and custom parsers.

def get_click_type(
annotation: Any,
parameter_info: ParameterInfo
) - > click.ParamType

Determines the appropriate Click parameter type based on a Python type annotation and additional parameter metadata. This function maps standard Python types, Enums, and file-like objects to their corresponding Click validation and conversion logic.

Parameters​

NameTypeDescription
annotationAnyThe Python type hint or class used to infer the base Click data type (e.g., int, str, Path, or Enum).
parameter_infoParameterInfoAn object containing metadata such as min/max ranges, file permissions, date formats, and custom parsers that refine the Click type configuration.

Returns​

TypeDescription
click.ParamTypeA Click parameter type instance configured with validation constraints like ranges, file modes, or choice sets.