python / python/mypy

no error when method in metaclass is overridden by an incompatible method in its instance

Open
#17,966 0 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

class Foo(type):
    def foo(cls) -> None: ...


class Bar(Foo):
    def asdf(cls) -> None:
        cls.foo()


class Baz(metaclass=Bar):
    # no error.
    # at runtime it raises TypeError: Baz.foo() missing 2 required positional arguments: 'self' and 'asdf'
    def foo(self, asdf: int) -> None: ...


Baz.asdf()

playground

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 with the linked mypy-play reproduction and trace how mypy checks members across a metaclass and its instance. Add coverage for the example; done means the unsound call is diagnosed and the regression test passes.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.