Skip to content

Operator dunder methods (Block, Plug) lose type hints in docs — oodebug wrapper missing @functools.wraps #78

Description

@petercorke

Building the Sphinx docs (sphinx-build -b html docs/source ...) currently emits 22 warnings like:

src/bdsim/components.py:39: WARNING: Cannot handle as a local function: "bdsim.Block.__add__" (use @functools.wraps) [sphinx_autodoc_typehints.local_function]
src/bdsim/connect.py:19: WARNING: Cannot handle as a local function: "bdsim.Plug.__add__" (use @functools.wraps) [sphinx_autodoc_typehints.local_function]

— one for every operator dunder method on Block (block.py) and Plug (connect.py) that's wrapped by the local oodebug decorator (__add__, __radd__, __sub__, __rsub__, __mul__, __rmul__, __truediv__, __rtruediv__, __pow__, __neg__, __rshift__ — 11 methods × 2 classes = 22).

Root cause: oodebug is defined twice (connect.py:18, near-identically in components.py:38 — the latter's comment says it's "kept local to avoid an import cycle with components.py"), and neither wrapper uses functools.wraps:

def oodebug(func: _F) -> _F:
    def wrapper(*args: Any, **kwargs: Any) -> Any:
        ret = func(*args, **kwargs)
        return ret
    return wrapper  # type: ignore[return-value]

Without functools.wraps(func) on wrapper, sphinx_autodoc_typehints (and anything else that introspects __wrapped__/__signature__, eg. inspect.signature) sees wrapper(*args, **kwargs) instead of the real operator signature — so these 22 methods render without proper type hints in the rendered API docs at https://petercorke.github.io/bdsim/.

Suggested fix: add @functools.wraps(func) to wrapper in both oodebug definitions. Low risk — oodebug is a no-op passthrough already (the debug print is commented out), so this only affects introspection, not runtime behavior.

Found while auditing the Sphinx docs build for warnings — not fixed here since it touches block/plug operator-overload source rather than documentation.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    tech-debtKnown technical debt, tracked for a deliberate future revisit

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions