Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dynamic_cast-0.1.2a1.tar.gz (6.6 kB view hashes)

Uploaded Source

Built Distribution

dynamic_cast-0.1.2a1-py3-none-any.whl (8.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page