Introspection
provide.foundation.hub.introspection
¶
Framework-agnostic parameter introspection.
This module provides utilities to extract parameter information from function signatures in a framework-agnostic way, supporting modern Python type hints including typing.Annotated for CLI rendering hints.
Classes¶
ParameterInfo
¶
Framework-agnostic parameter information.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Parameter name |
type_annotation |
Any
|
Original type annotation (may be Annotated) |
concrete_type |
type
|
Extracted concrete type (for Click/other frameworks) |
default |
Any
|
Default value (inspect.Parameter.empty if required) |
has_default |
bool
|
Whether parameter has a default value |
is_required |
bool
|
Whether parameter is required (inverse of has_default) |
cli_hint |
str | None
|
Explicit CLI rendering hint ('argument', 'option', or None) |
Functions¶
extract_cli_hint
¶
Extract CLI rendering hint from Annotated type.
Supports typing.Annotated with string metadata to explicitly control whether a parameter becomes a CLI argument or option.
Handles both runtime Annotated types and string annotations from
from __future__ import annotations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
annotation
|
Any
|
Type annotation (may be Annotated[type, 'hint'] or string) |
required |
param_name
|
str
|
Parameter name (for error messages) |
required |
Returns:
| Type | Description |
|---|---|
tuple[Any, str | None]
|
(base_type, hint) where hint is 'argument', 'option', or None |
Raises:
| Type | Description |
|---|---|
InvalidCLIHintError
|
If hint is not 'argument' or 'option' |
Examples:
Source code in provide/foundation/hub/introspection.py
introspect_parameters
¶
Extract parameter information from function signature.
Introspects a function's parameters and returns framework-agnostic metadata that can be used by different CLI adapters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable[..., Any]
|
Function to introspect |
required |
Returns:
| Type | Description |
|---|---|
list[ParameterInfo]
|
List of ParameterInfo objects (excludes 'self', 'cls', 'ctx') |
Examples:
>>> def greet(name: str, greeting: str = "Hello"):
... pass
>>> params = introspect_parameters(greet)
>>> len(params)
2
>>> params[0].name
'name'
>>> params[0].is_required
True
>>> params[1].has_default
True