Skip to content

Mypy doesn't show errors when base method has *args: Any or **kwargs: Any #18980

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
denisshaf opened this issue Apr 27, 2025 · 2 comments
Closed
Labels
bug mypy got something wrong

Comments

@denisshaf
Copy link

Bug Report

If the base class / prototype has a method that accepts only *args: Any or / and **kwargs: Any, mypy doesn't show any errors, even if the child class accepts only limited set of parameters. If I add a: int to foo in the base class, nothing changes. If I add b: int to foo in the base class, mypy show an error "Signature of "foo" incompatible with supertype "HasFoo"", that is expected.

To Reproduce

from typing import Protocol, Any


class HasFoo:
    def foo(self, *arg: Any, **kwargs: Any) -> str: return 'foo'


class Foo(HasFoo):
    def foo(self, a: int) -> str:
        print(a)
        return 'foo'
        

f: HasFoo = Foo()
f.foo(3, 4, 5)

Gist URL: https://gist.github.com/mypy-play/1a858925c056f8b5391e09a247b29ece
Playground URL: https://mypy-play.net/?mypy=latest&python=3.13&gist=1a858925c056f8b5391e09a247b29ece

Expected Behavior

Mypy should raise an error "Signature of "foo" incompatible with supertype "HasFoo"".

Actual Behavior

Mypy doesn't raise any errors. The code above fails in runtime.

Your Environment

  • Mypy version used: 1.15.0
  • Mypy command-line flags: -
  • Mypy configuration options from mypy.ini (and other config files):
[tool.mypy]
disallow_untyped_defs = true
disallow_any_unimported = true
no_implicit_optional = true
check_untyped_defs = true
warn_return_any = true
warn_unused_ignores = true
packages = ['src']
  • Python version used: 3.13.3
@denisshaf denisshaf added the bug mypy got something wrong label Apr 27, 2025
@TeamSpen210
Copy link
Contributor

This is intentional behaviour. The combination of *args: Any and **kwargs: Any is special, allowing any possible signature.

@A5rocks
Copy link
Collaborator

A5rocks commented Apr 27, 2025

And *args: Any by itself is also intentionally special. (Due to type var tuples)

@A5rocks A5rocks closed this as not planned Won't fix, can't repro, duplicate, stale Apr 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

3 participants