python / python/mypy

(🐞) `(*args: Any)` acts inconsistently to how `(*args: Any, **kwargs: Any)` behaves

Open
#16,578 0 comments 4 reactions 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

(*args: Any) acts inconsistently to how (*args: Any, **kwargs: Any) behaves:

# mypy: disable-error-code=empty-body
from __future__ import annotations

from typing import Any, Protocol

class Base:
    def f1(self, x: int, *args: Any) -> None: ...
    def f2(self, x: int, *args: Any, **kwargs: Any) -> None: ...

class Derived(Base):
    def f1(self, x: int, y: str) -> None: ...  # Signature of "f1" incompatible with supertype "Base"
    def f2(self, x: int, y: str) -> None: ...

Given that the rest of the arguments after x in Derived.f1 are positional, I would expect this to be a compatible subtype.

  • related #16569

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

Start by running the supplied mypy reproduction and compare the compatibility results for f1 and f2. Trace the type-checking path for overriding methods and determine what behavior should make the two signatures consistent; done when the example produces the expected compatibility result without regressing related override checks.

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
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.