haive.core.utils.enhanced_naming¶
Enhanced naming utilities for complex type annotations and tool names.
This module provides advanced utilities for sanitizing complex Python type annotations and generic classes into OpenAI-compliant tool names with descriptive transformations.
Key Features: - Handles nested generics: List[Dict[str, Task]] -> list_dict_str_task_nested_generic - Provides transformation descriptions for debugging - Handles Union, Optional, and complex type annotations - Maintains type hierarchy information in the name - Supports custom naming strategies
Examples
Complex type handling:
from haive.core.utils.enhanced_naming import enhanced_sanitize_tool_name
# Nested generics
result, desc = enhanced_sanitize_tool_name("List[Dict[str, Task]]")
# Returns: ("list_dict_str_task_nested_generic", "3-level nested generic with 4 type parameters")
# Union types
result, desc = enhanced_sanitize_tool_name("Union[str, List[Task]]")
# Returns: ("union_str_list_task_generic", "Union type with 2 alternatives")
# Optional types
result, desc = enhanced_sanitize_tool_name("Optional[Plan[Task]]")
# Returns: ("optional_plan_task_generic", "Optional type wrapping Plan[Task] generic")
Classes¶
Advanced parser for complex generic type annotations. |
|
Metadata about a naming transformation. |
Functions¶
|
Analyze naming complexity across multiple type names. |
|
Enhanced tool name sanitization with metadata and complex type support. |
|
Get multiple enhanced naming suggestions with metadata. |
Enhanced Pydantic model name sanitization with metadata. |
Module Contents¶
- class haive.core.utils.enhanced_naming.EnhancedGenericParser[source]¶
Advanced parser for complex generic type annotations.
- class haive.core.utils.enhanced_naming.NamingTransformation[source]¶
Metadata about a naming transformation.
- haive.core.utils.enhanced_naming.analyze_naming_complexity(type_names)[source]¶
Analyze naming complexity across multiple type names.
- Parameters:
- Returns:
Dictionary with complexity analysis results
- Return type:
Examples
>>> results = analyze_naming_complexity([ ... "Plan[Task]", ... "List[Dict[str, Task]]", ... "Union[str, Optional[Plan[Task]]]" ... ]) >>> print(f"Average complexity: {results['average_complexity']}") >>> print(f"Most complex: {results['most_complex']['name']}")
- haive.core.utils.enhanced_naming.enhanced_sanitize_tool_name(raw_name, include_metadata=True, max_complexity=5)[source]¶
Enhanced tool name sanitization with metadata and complex type support.
- Parameters:
- Returns:
Tuple of (sanitized_name, transformation_metadata)
- Return type:
tuple[str, NamingTransformation | None]
Examples
>>> name, meta = enhanced_sanitize_tool_name("List[Dict[str, Task]]") >>> print(name) 'list_dict_str_task_nested_generic' >>> print(meta.description) '3-level nested generic with 4 type parameters'
>>> name, meta = enhanced_sanitize_tool_name("Union[str, Optional[Plan[Task]]]") >>> print(name) 'union_str_optional_plan_task_generic' >>> print(meta.complexity_level) 2
- haive.core.utils.enhanced_naming.get_naming_suggestions_enhanced(raw_name, count=5)[source]¶
Get multiple enhanced naming suggestions with metadata.
- haive.core.utils.enhanced_naming.sanitize_pydantic_model_name_enhanced(model)[source]¶
Enhanced Pydantic model name sanitization with metadata.
- Return type:
tuple[str, NamingTransformation | None]