func-args is a lightweight Python library (current version 1.0.1) designed for creating wrapper functions with enhanced argument handling. It addresses common challenges encountered with third-party APIs that have suboptimal interface designs, allowing developers to explicitly mark parameters as required or optional using special sentinel values (REQ and OPT). The library is actively maintained with a stable release cadence.
pip install func-argsVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to define a function using the `@delegator` decorator and `REQ`/`OPT` sentinel values. `REQ` marks a parameter as mandatory, ensuring a `TypeError` is raised if it's not provided. `OPT` acts as a placeholder for optional parameters, allowing you to differentiate between an explicitly passed `None` and an omitted optional argument.
Use `if my_param is not OPT:` to check if an optional argument was truly provided, rather than `if my_param is not None:` if `None` is a valid explicit value.
Ensure all parameters marked with `REQ` are always provided when calling the function. The `TypeError` message will indicate which required argument is missing.
For mutable default arguments, always initialize the mutable object inside the function if the argument is `OPT` (or `None` if `OPT` is not used), e.g., `if my_list is OPT: my_list = []`.
No dependency data recorded yet.