Skip to content

redundant-numeric-union (PYI041) --fix incorrect fix for functools.singledispatch registered function #27333

Description

@agalasso

Summary

Applying PYI041 --fix will replace a numeric union annotation like int | float with float, but this is an incorrect fix for a method that is annotated with @func.register for a functools.singledispatch function.
Minimal example code:

import functools

@functools.singledispatch
def int_or_float(value: object) -> str:
    return False

@int_or_float.register
def _(value: int | float):
    return True

assert int_or_float(3)

Repro script:

repro-ruff-redundant-numeric-union-singledispatch.sh

Version

ruff 0.16.0 (did not check any other versions)

Activity

  1. ntBre commented on Jul 30, 2026

    @ntBre
    Contributor

    Thanks for the report! Seems like the rule should not apply to singledispatch functions.

  2. self-assigned this
    on Jul 30, 2026
  3. added
    bugAn issue describing something that isn't working, or a PR that fixes a bug
    on Jul 30, 2026
  4. added a commit that references this issue on Jul 31, 2026
    31cb63a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugAn issue describing something that isn't working, or a PR that fixes a bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions