Python supercharged for fastai development
56
Build a configuration file parser that reads various data formats and converts them to appropriate Python types with validation.
Your parser should handle conversion of string values from configuration files into appropriate Python types.
The parser should convert various input formats into lists.
The parser should provide safe conversion with default values when conversion fails or input is None.
@generates
def parse_value(value: str, target_type: str):
"""
Parse a string value to the target type.
Args:
value: String value to parse
target_type: Target type name ('bool', 'int', 'float', 'list')
Returns:
Parsed value in the target type
Raises:
ValueError: If conversion fails
"""
pass
def safe_convert(value, converter, default=None):
"""
Safely convert a value using a converter function with fallback.
Args:
value: Value to convert (can be None)
converter: Function to use for conversion
default: Default value if conversion fails or value is None
Returns:
Converted value or default
"""
pass
def ensure_list(value, default=None):
"""
Ensure value is a list, converting single values or using default.
Args:
value: Value to convert to list
default: Default value if value is None
Returns:
List containing the value(s)
"""
passProvides type conversion and validation utilities.
@satisfied-by
Install with Tessl CLI
npx tessl i tessl/pypi-fastcoredocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10