strast.factory
1from . import c 2 3 4def strast( 5 *default_only_types, 6 default_grab_types=None, 7 default_force_ast=False, 8 default_force_str=False 9): 10 """ 11 Factory function to create a configured `strast.core.strast` function with specific default behaviors. 12 13 This factory allows for pre-configuring the `strast.core.strast` function with specific default parameters, 14 such as type-checking (`default_only_types`), AST enforcement (`default_force_ast`), 15 automatic type detection (`default_grab_types`), and ensuring the input is strictly a string (`default_force_str`). 16 17 Args: 18 *default_only_types (type or Any): Default types for the result when using the generated function. 19 default_grab_types (bool or None, optional): Default setting for automatic type deduction. 20 default_force_ast (bool, optional): Default setting for enforcing AST representation. 21 default_force_str (bool, optional): Default setting for ensuring input is a string. 22 23 Returns: 24 function: A `strast` function pre-configured with the provided default settings. 25 26 Usage: 27 >>> import strast 28 >>> custom_strast = strast.f(int, default_force_str=True) 29 >>> custom_strast("123") # Uses default settings from the factory 30 123 31 32 >>> custom_strast("123", float) # Overrides the default settings 33 ValueError: Expected result type to be among (<class 'float'>,), but got <class 'int'>. 34 """ 35 36 def strast_closure( 37 val, *only_types, grab_types=None, force_ast=False, force_str=False 38 ): 39 if grab_types is None: 40 grab_types = default_grab_types 41 if force_ast is None: 42 force_ast = default_force_ast 43 if force_str is None: 44 force_str = default_force_str 45 if not only_types: 46 only_types = default_only_types 47 48 return c( 49 val, 50 *only_types, 51 grab_types=grab_types, 52 force_ast=force_ast, 53 force_str=force_str 54 ) 55 56 return strast_closure
def
strast( *default_only_types, default_grab_types=None, default_force_ast=False, default_force_str=False):
5def strast( 6 *default_only_types, 7 default_grab_types=None, 8 default_force_ast=False, 9 default_force_str=False 10): 11 """ 12 Factory function to create a configured `strast.core.strast` function with specific default behaviors. 13 14 This factory allows for pre-configuring the `strast.core.strast` function with specific default parameters, 15 such as type-checking (`default_only_types`), AST enforcement (`default_force_ast`), 16 automatic type detection (`default_grab_types`), and ensuring the input is strictly a string (`default_force_str`). 17 18 Args: 19 *default_only_types (type or Any): Default types for the result when using the generated function. 20 default_grab_types (bool or None, optional): Default setting for automatic type deduction. 21 default_force_ast (bool, optional): Default setting for enforcing AST representation. 22 default_force_str (bool, optional): Default setting for ensuring input is a string. 23 24 Returns: 25 function: A `strast` function pre-configured with the provided default settings. 26 27 Usage: 28 >>> import strast 29 >>> custom_strast = strast.f(int, default_force_str=True) 30 >>> custom_strast("123") # Uses default settings from the factory 31 123 32 33 >>> custom_strast("123", float) # Overrides the default settings 34 ValueError: Expected result type to be among (<class 'float'>,), but got <class 'int'>. 35 """ 36 37 def strast_closure( 38 val, *only_types, grab_types=None, force_ast=False, force_str=False 39 ): 40 if grab_types is None: 41 grab_types = default_grab_types 42 if force_ast is None: 43 force_ast = default_force_ast 44 if force_str is None: 45 force_str = default_force_str 46 if not only_types: 47 only_types = default_only_types 48 49 return c( 50 val, 51 *only_types, 52 grab_types=grab_types, 53 force_ast=force_ast, 54 force_str=force_str 55 ) 56 57 return strast_closure
Factory function to create a configured strast.core.strast function with specific default behaviors.
This factory allows for pre-configuring the strast.core.strast function with specific default parameters,
such as type-checking (default_only_types), AST enforcement (default_force_ast),
automatic type detection (default_grab_types), and ensuring the input is strictly a string (default_force_str).
Arguments:
- *default_only_types (type or Any): Default types for the result when using the generated function.
- default_grab_types (bool or None, optional): Default setting for automatic type deduction.
- default_force_ast (bool, optional): Default setting for enforcing AST representation.
- default_force_str (bool, optional): Default setting for ensuring input is a string.
Returns:
function: A
strastfunction pre-configured with the provided default settings.
Usage:
>>> import strast >>> custom_strast = strast.f(int, default_force_str=True) >>> custom_strast("123") # Uses default settings from the factory 123>>> custom_strast("123", float) # Overrides the default settings ValueError: Expected result type to be among (<class 'float'>,), but got <class 'int'>.