This Python module provides a dynamic casting utility that enables flexible casting of function arguments and return values based on type annotations. The utility is particularly useful for handling complex type conversions and ensuring compatibility between different data types.
Install dynamic-cast via pip:
pip install dynamic-cast
The dynamic_cast
function can be applied to functions to dynamically cast their arguments and return values based on the provided type annotations. It supports various scenarios, including handling iterable types, callables, and more.
@dynamic_cast
def example_function(arg1: int, arg2: str) -> float:
# Function logic here.
return result
For more advanced scenarios, the utility provides additional functionality, such as handling generic types, callable types, and class instances.
@dynamic_cast
def advanced_function(arg1: List[int], arg2: Dict[str, float]) -> Tuple[str, int]:
# Advanced function logic here.
return result_tuple
...
Feel free to contribute to the development of this dynamic casting utility. If you encounter any issues or have suggestions for improvement, please create an issue or submit a pull request.
This dynamic casting utility is distributed under the MIT License. See the LICENSE file for more information.