Skip to content

Incompatible signature with superclass with variadic arguments when overriding with definite arguments #5364

Closed
@scolby33

Description

@scolby33

I have two classes defined like so:

# test.py
from typing import Any

class MyBase:
    def __init__(self, *args: Any, **kwargs: Any) -> None:
        self.override_me(*args, **kwargs)

    def override_me(self, *args: Any, **kwargs: Any) -> None:
        pass


class MyHeir(MyBase):
    def override_me(self, message: str) -> None:
        print(message)

And the corresponding mypy output:
test.py:13: error: Signature of "override_me" incompatible with supertype "MyBase"

Now, I'm a bit new to this typing thing and don't have a background in type theory, but in my mind, these signatures are compatible, even though I can see why mypy would disagree.

Is there a better way to notate the types here? Is there a way to override this in mypy except for preventing all type checking on the "wrong" lines?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions