{"library":"backcall","title":"backcall","description":"backcall is a Python module designed to create backwards-compatible callback APIs. It enables developers to add new parameters to API calls without breaking existing third-party callback functions that may not be aware of these new parameters. The library is currently at version 0.2.0, last released on June 9, 2020, and appears to be in a maintenance state with infrequent updates.","status":"maintenance","version":"0.2.0","language":"en","source_language":"en","source_url":"https://github.com/takluyver/backcall","tags":["callbacks","api design","backwards compatibility","signature introspection"],"install":[{"cmd":"pip install backcall","lang":"bash","label":"Install with pip"}],"dependencies":[],"imports":[{"symbol":"callback_prototype","correct":"from backcall import callback_prototype"}],"quickstart":{"code":"from backcall import callback_prototype\n\n@callback_prototype\ndef my_prototype_handler(sender, message, detail=None):\n    # This function defines the expected signature for callbacks.\n    # Positional parameters without defaults, keyword-only with defaults (Python 3).\n    pass\n\ndef register_event_handler(callback_func):\n    # The adapt method inspects the callback and wraps it if necessary\n    # to discard extra arguments not in the prototype.\n    adapted_callback = my_prototype_handler.adapt(callback_func)\n    print(f\"Registered adapted callback: {adapted_callback.__name__}\")\n    return adapted_callback\n\n# Example callbacks\ndef simple_callback(sender, message):\n    print(f\"Simple: {sender} says '{message}'\")\n\ndef detailed_callback(sender, message, detail):\n    print(f\"Detailed: {sender} says '{message}' with detail: {detail}\")\n\ndef super_detailed_callback(sender, message, detail, extra_arg='default'):\n    print(f\"Super Detailed: {sender} says '{message}' with detail: {detail} and extra: {extra_arg}\")\n\n# Registering and calling\nprint(\"--- Registering simple_callback ---\")\nadapted_simple = register_event_handler(simple_callback)\nadapted_simple('System', 'Hello world!')\n\nprint(\"--- Registering detailed_callback ---\")\nadapted_detailed = register_event_handler(detailed_callback)\nadapted_detailed('System', 'Another message', 'Important info')\n\n# This would normally raise TypeError if passed to .adapt directly, \n# but backcall will raise it because the callback has *more* arguments than prototype.\nprint(\"\\n--- Attempting to register super_detailed_callback (expecting TypeError) ---\")\ntry:\n    register_event_handler(super_detailed_callback)\nexcept TypeError as e:\n    print(f\"Caught expected error: {e}\")","lang":"python","description":"To use `backcall`, define a 'callback prototype' function using the `@callback_prototype` decorator. This prototype's signature specifies all parameters that your API might pass. Then, use the `prototype.adapt(callback)` method to inspect and potentially wrap user-provided callback functions. If a callback takes fewer arguments than the prototype, `adapt` creates a wrapper that discards the extra arguments. If a callback takes *more* arguments than the prototype, `adapt` will raise a `TypeError`."},"warnings":[{"fix":"Ensure that any callback function you pass to `prototype.adapt()` has a signature that is a subset of or exactly matches the prototype's signature. Remove any extra parameters from the callback that are not present in the prototype.","message":"Callback functions provided to `prototype.adapt()` cannot have *more* arguments than defined in the `callback_prototype`, even if those extra arguments have default values. Doing so will result in a `TypeError` when the callback is registered.","severity":"gotcha","affected_versions":"0.2.0 and earlier"},{"fix":"If using a compiled function, wrap it in a standard Python `def` function to expose an introspectable signature to `backcall`.","message":"Callback functions must have introspectable signatures. This means functions defined in compiled code (e.g., C extensions) cannot be directly used as callbacks unless they are wrapped in a Python function.","severity":"gotcha","affected_versions":"0.2.0 and earlier"},{"fix":"Factor in the project's maintenance status when planning long-term dependencies or if requiring new features/bug fixes. Consider vendoring the code if deep customization or active support becomes critical.","message":"The project appears to be in a maintenance state, with the last release in June 2020 and minimal recent activity on its GitHub repository. While widely used, be aware that active development and new features are unlikely.","severity":"gotcha","affected_versions":"0.2.0 and later (due to project status)"}],"env_vars":null,"last_verified":"2026-04-05T00:00:00.000Z","next_check":"2026-07-04T00:00:00.000Z"}