{"id":5232,"library":"func-args","title":"Function Argument Wrapper for Enhanced Handling","description":"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.","status":"active","version":"1.0.1","language":"en","source_language":"en","source_url":"https://github.com/MacHu-GWU/func_args-project","tags":["function arguments","decorators","argument handling","sentinel values","wrapper functions"],"install":[{"cmd":"pip install func-args","lang":"bash","label":"Install func-args"}],"dependencies":[],"imports":[{"symbol":"delegator","correct":"from func_args import delegator"},{"symbol":"REQ","correct":"from func_args import REQ"},{"symbol":"OPT","correct":"from func_args import OPT"}],"quickstart":{"code":"from func_args import REQ, OPT, delegator\n\n@delegator\ndef my_function(required_param: REQ, optional_param: OPT = None):\n    \"\"\"An example function using REQ and OPT for argument handling.\"\"\"\n    print(f\"Required: {required_param}\")\n    if optional_param is not OPT:\n        print(f\"Optional: {optional_param}\")\n    else:\n        print(\"Optional parameter was not provided.\")\n    return {\"required\": required_param, \"optional\": optional_param}\n\n# Example 1: Providing both required and optional\nresult1 = my_function(required_param=\"hello\", optional_param=\"world\")\nprint(f\"Result 1: {result1}\")\n\n# Example 2: Providing only required, optional defaults to OPT sentinel\nresult2 = my_function(required_param=123)\nprint(f\"Result 2: {result2}\")\n\n# Example 3: Missing a required argument (will raise TypeError)\ntry:\n    my_function()\nexcept TypeError as e:\n    print(f\"Error: {e}\")","lang":"python","description":"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."},"warnings":[{"fix":"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.","message":"The `OPT` sentinel value is distinct from `None`. When an optional parameter is not provided, its value will be the `OPT` object, not `None`. Always check `if my_param is not OPT:` if you need to differentiate an omitted argument from an explicit `None`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure all parameters marked with `REQ` are always provided when calling the function. The `TypeError` message will indicate which required argument is missing.","message":"Omitting a parameter marked with `REQ` will result in a `TypeError`, as the `delegator` decorator enforces its presence. This behavior ensures explicit argument handling and early error detection.","severity":"breaking","affected_versions":"All versions"},{"fix":"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 = []`.","message":"While `func-args` provides a mechanism for explicit argument handling, it does not directly prevent the general Python 'mutable default argument' footgun. If you assign a mutable object (like a list or dictionary) as a default value to a parameter *not* using `OPT`, that object will be shared across all calls to the function.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-13T00:00:00.000Z","next_check":"2026-07-12T00:00:00.000Z"}