---
id: void-helper
description: "Learn when and how to use pyDeprecate's void(...) helper to silence IDE warnings in deprecated stubs. Compare pass and docstring-only alternatives, and understand type-checking interactions."
---

# The void(...) Helper

When `@deprecated` forwards to a `target` callable, the deprecated function's body **never runs** — every call is intercepted before the body executes. This creates a practical annoyance: IDEs and linters see the parameters in the signature but nothing using them in the body, and they flag them as unused.

`void(...)` is a *no-op* that accepts any arguments and returns `None`. Its only job is to silence those IDE warnings by giving the parameters a nominal "use" that says: the body is intentionally empty, not accidentally incomplete. It has **no runtime effect**.

## When to use void(...)

Use `void(...)` when *all three* of these are true:

- The deprecated function forwards to a `target` callable (not `TargetMode.NOTIFY` or `TargetMode.ARGS_REMAP`).
- Your IDE or linter flags the function parameters as unused.
- You want the code to clearly signal that the empty body is deliberate.

If you prefer, a bare `pass` or a standalone docstring are equally valid. pyDeprecate does **not require** `void(...)`. Use whichever form is clearest for your team.

## Basic usage

`void(...)` appears as the return expression of a deprecated wrapper. The call to `add` is forwarded to `add_values` immediately, so the `return void(a, b)` line is never reached. It tells the IDE that `a` and `b` are intentionally accepted and ignored.

```python
# NEW API — adds two integers and returns the sum
def add_values(a: int, b: int) -> int:
    return a + b


# ---------------------------

from deprecate import deprecated, void


# DEPRECATED API — `add` replaced by `add_values`
@deprecated(target=add_values, deprecated_in="1.0", remove_in="2.0")
def add(a: int, b: int) -> int:
    return void(a, b)  # Tells IDE: "Yes, I know these parameters aren't used"
    # This line is never reached - call is forwarded to add_values


# Alternative: You can also use pass or just a docstring
@deprecated(target=add_values, deprecated_in="1.0", remove_in="2.0")
def add_v1(a: int, b: int) -> int:
    """Just a docstring works too."""
    pass  # This also works


print(add_v1(2, 3))
```

<details>
  <summary>Output: <code>add_v1(2, 3)</code></summary>

```
5
```

</details>

## Alternatives to void(...)

There are three common patterns for the body of a deprecated function that forwards to a target. All are *equivalent at runtime* because the body is never reached. The choice is about communicating intent to readers and static analysis.

### Option 1: `pass` statement

`pass` is the simplest approach and clear, idiomatic Python for "do nothing". IDEs may still flag the parameters as unused since nothing references them.

```python
from deprecate import deprecated


# NEW API — evaluates the sum of two integers
def evaluate(x: int, y: int) -> int:
    return x + y


# DEPRECATED API — `compute` replaced by `evaluate`
@deprecated(target=evaluate, deprecated_in="1.0", remove_in="2.0")
def compute(x: int, y: int) -> int:
    pass


print(compute(2, 3))
```

<details>
  <summary>Output: <code>compute(2, 3)</code></summary>

```
5
```

</details>

### Option 2: Docstring-only body

A docstring alone is a valid function body. It is useful when you want to document what the deprecated function did historically or provide migration notes inline.

```python
from deprecate import deprecated


# NEW API — evaluates the sum of two integers
def evaluate(x: int, y: int) -> int:
    return x + y


# DEPRECATED API — `compute` replaced by `evaluate`
@deprecated(target=evaluate, deprecated_in="1.0", remove_in="2.0")
def compute(x: int, y: int) -> int:
    """Previously computed x + y. Use evaluate() directly."""


print(compute(2, 3))
```

<details>
  <summary>Output: <code>compute(2, 3)</code></summary>

```
5
```

</details>

### Option 3: `void(...)` call

`void(...)` references all parameters explicitly, silencing "unused parameter" warnings in PyCharm, VS Code (Pylance), and ruff. It also serves as a visual marker that the empty body is intentional.

```python
from deprecate import deprecated, void


# NEW API — evaluates the sum of two integers
def evaluate(x: int, y: int) -> int:
    return x + y


# DEPRECATED API — `compute` replaced by `evaluate`
@deprecated(target=evaluate, deprecated_in="1.0", remove_in="2.0")
def compute(x: int, y: int) -> int:
    return void(x, y)


print(compute(2, 3))
```

<details>
  <summary>Output: <code>compute(2, 3)</code></summary>

```
5
```

</details>

### Comparison summary

| Approach       | Silences unused-param warnings | Self-documenting intent | Extra import                       |
| -------------- | ------------------------------ | ----------------------- | ---------------------------------- |
| `pass`         | No                             | Moderate                | No                                 |
| Docstring only | No                             | High (can explain why)  | No                                 |
| `void(...)`    | Yes                            | High (explicit no-op)   | Yes (`from deprecate import void`) |

If you use a strict linter that flags unused parameters (e.g. ruff's `ARG001`), `void(...)` is the cleanest solution that does not require `# noqa` comments.

## void(...) in generator stubs

A deprecated generator stub <u>must still contain</u> `yield`. The wrapper kind follows the stub.

!!! warning "A plain stub gets a plain wrapper"

    A stub whose body is only `return void(...)` is a plain function. Its wrapper is therefore a plain function that warns at call time. `inspect.isgeneratorfunction` reports `False`, even when the target is a generator.

Call `void(...)` as a statement and add `yield from ()` so the stub stays a generator function. See [Advanced](advanced.md) for a full example.

## void(...) with methods

`void(...)` works identically in class methods. Reference `self` and all parameters when forwarding a deprecated method:

```python
from deprecate import deprecated, void


class ImageProcessor:
    def resize(self, width: int, height: int, interpolation: str = "bilinear") -> str:
        return f"Resized to {width}x{height} ({interpolation})"

    @deprecated(target=resize, deprecated_in="2.0", remove_in="3.0")
    def scale(self, width: int, height: int, interpolation: str = "bilinear") -> str:
        """Deprecated — renamed to resize()."""
        return void(width, height, interpolation)


proc = ImageProcessor()
print(proc.scale(800, 600))
```

<details>
  <summary>Output: <code>proc.scale(800, 600)</code></summary>

```
Resized to 800x600 (bilinear)
```

</details>

You do **not** need to pass `self` to `void(...)` — only the parameters your linter flags. `self` is implicitly used by method dispatch and is never flagged.

## Type annotation note

!!! info "No action needed in most cases"

    Modern versions of mypy and pyright handle decorated functions correctly and do not flag the return type mismatch in dead code paths. The workarounds below are only needed if your type checker explicitly complains.

`void(...)` returns `None`, which looks incompatible with a function annotated as `-> int`. In practice this is fine because:

1. **The body never runs.** `@deprecated` intercepts the call and forwards to the target before the body executes. The `return void(...)` line is dead code.
2. **Type checkers handle dead code leniently.** Since mypy and pyright can see the decorator, they generally do not flag return type mismatches in unreachable paths.
3. **If your type checker does complain**, two workarounds:

```python
from deprecate import deprecated, void
from typing import Any, cast


# NEW API — doubles the input value; replaces the deprecated score wrappers
def score_predictions(x: int) -> int:
    return x * 2


# Option A: Use `pass` instead (no return statement at all)
# DEPRECATED API — `transform_a` replaced by `score_predictions`
@deprecated(target=score_predictions, deprecated_in="1.0", remove_in="2.0")
def transform_a(x: int) -> int:
    pass  # type: ignore[return-value]


# Option B: Cast the void return (technically dead code)
# DEPRECATED API — `transform_b` replaced by `score_predictions`
@deprecated(target=score_predictions, deprecated_in="1.0", remove_in="2.0")
def transform_b(x: int) -> int:
    return cast(int, void(x))


print(transform_b(2))
```

<details>
  <summary>Output: <code>transform_b(2)</code></summary>

```
4
```

</details>

In practice, neither workaround is usually needed — modern versions of mypy handle decorated functions correctly and do not flag unreachable return statements.

## void(...) vs assert_no_warnings

These two utilities solve *completely different* problems. Their names might suggest a connection, but they operate in different contexts. `assert_no_warnings` is a test-time tool covered in [Testing Deprecated Code](../integrations/testing.md#testing-deprecated-code).

|                    | `void(...)`                                                | `assert_no_warnings()`                                                  |
| ------------------ | ---------------------------------------------------------- | ----------------------------------------------------------------------- |
| **Purpose**        | Silence IDE "unused parameter" warnings in function bodies | Assert that no warnings of a given type are emitted during a code block |
| **Where used**     | Inside the body of a deprecated function stub              | In test code, as a context manager                                      |
| **Runtime effect** | None (accepts args, returns `None`)                        | Captures warnings and raises `AssertionError` if any match              |
| **Import**         | `from deprecate import void`                               | `from deprecate import assert_no_warnings`                              |

```python
from deprecate import deprecated, void, assert_no_warnings


# NEW API — doubles the input value
def score_predictions(x: int) -> int:
    return x * 2


# void() — used in the deprecated function body (decoration-time concern)
# DEPRECATED API — `score` replaced by `score_predictions`
@deprecated(target=score_predictions, deprecated_in="1.0", remove_in="2.0")
def score(x: int) -> int:
    return void(x)


# assert_no_warnings — used in tests (runtime assertion concern)
with assert_no_warnings(FutureWarning):
    # Verify that calling the NEW function does not trigger any deprecation warning
    result = score_predictions(42)
print(result)
```

<details>
  <summary>Output: <code>score_predictions(42)</code></summary>

```
84
```

</details>

## See also

- [Use Cases](index.md) covers worked examples of deprecation patterns, including those that use `void()`.
- [Troubleshooting](../troubleshooting.md) explains which `deprecated_instance` operators warn and which stay silent.

______________________________________________________________________

Next: [Audit Tools](../audit/index.md) — validate decorator configuration, enforce removal deadlines, and detect deprecation chains in CI.
