python / python/mypy

Incompatible signature using `singledispatchmethod` in a subclass

Open
#14,742 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Bug Report

Mypy can't handle singledispatchmethod overloading a method in a subclass

To Reproduce

from functools import singledispatchmethod


class A:
    def foo(self, bar: object) -> object:
        return True


class B(A):
    @singledispatchmethod
    def foo(self, bar: object) -> object:
        return super().foo(bar)

    @foo.register
    def int_impl(self, bar: int) -> int:
        return bar + 2

Expected Behavior

I wasn't expecting any error in this piece of code.

Actual Behavior

test.py:11: error: Signature of "foo" incompatible with supertype "A"  [override]
Found 1 error in 1 file (checked 1 source file)

My Environment

  • Mypy version used: 0.990
  • Python version used: 3.11

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no repository file or test; start by running the provided Python reproducer against mypy. Trace the incompatible-signature diagnostic around subclass overrides and singledispatchmethod handling, then add regression coverage and verify the example is accepted without errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.