A Python library for flexible type casting of function arguments and return values based on type annotations.
Project description
Dynamic Casting Utility
Introduction
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.
Installation
To use this dynamic casting utility, you can include it in your project by importing the dynamic_cast
function from the module.
from dynamic_cast import dynamic_cast
Usage
Basic Usage
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
Advanced Usage
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
Examples.
Dynamic Casting of Arguments.
@dynamic_cast
def example_function(arg1: Union[str, int], arg2: List[float]) -> Tuple[str, List[int]]:
# Function logic here
return result_tuple
Dynamic Casting of Class Instances
class ExampleClass:
@dynamic_cast
def __init__(self, arg1: int, arg2: str) -> None:
# Class initialization logic here
Contributing
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.
License
This dynamic casting utility is distributed under the MIT License. See the LICENSE file for more information.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file dynamic_cast-0.1.2a2.tar.gz
.
File metadata
- Download URL: dynamic_cast-0.1.2a2.tar.gz
- Upload date:
- Size: 6.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.18.2 CPython/3.10.14 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 80962cd3a9ba2f6310ed5c4fe6a27df9e1d4baf773fb2e604b15afb14a668b72 |
|
MD5 | 94bc5d4b35d0704661715cfae25d9e08 |
|
BLAKE2b-256 | cb8e87430a0882e10c611b6d7f38b3821614f7e17440d14b7dca2a37677af189 |
File details
Details for the file dynamic_cast-0.1.2a2-py3-none-any.whl
.
File metadata
- Download URL: dynamic_cast-0.1.2a2-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.18.2 CPython/3.10.14 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 18d2a1a61b9cdb3f6c9e283fc1e96312d3a39fc450ab5923c59c3e08e1dc326a |
|
MD5 | 08d94565aa6b2f7c2722a2e71447125d |
|
BLAKE2b-256 | 5e41673fa827bfc365a0d3b55707d0df5e7a2eecedd6aac9d79066ae4f2af6b6 |