Skip to content

Type mapping

provide.foundation.hub.type_mapping

Type system and Click type mapping utilities.

Functions

extract_click_type

extract_click_type(annotation: Any) -> type

Extract a Click-compatible type from a Python type annotation.

This is a wrapper around extract_concrete_type() that ensures compatibility with Click's type system.

Handles: - Union types (str | None, Union[str, None]) - Optional types (str | None) - Regular types (str, int, bool) - String annotations (from future import annotations)

Parameters:

Name Type Description Default
annotation Any

Type annotation from function signature

required

Returns:

Type Description
type

A type that Click can understand

Source code in provide/foundation/hub/type_mapping.py
def extract_click_type(annotation: Any) -> type:
    """Extract a Click-compatible type from a Python type annotation.

    This is a wrapper around extract_concrete_type() that ensures
    compatibility with Click's type system.

    Handles:
    - Union types (str | None, Union[str, None])
    - Optional types (str | None)
    - Regular types (str, int, bool)
    - String annotations (from __future__ import annotations)

    Args:
        annotation: Type annotation from function signature

    Returns:
        A type that Click can understand

    """
    return extract_concrete_type(annotation)