Skip to content

Argument incompatibility not detected with multiple generic base classes #6184

@ramosbugs

Description

@ramosbugs
  • Are you reporting a bug, or opening a feature request?

Reporting a bug

  • Please insert below the code you are checking with mypy,
    or a mock-up repro if the source is private. We would appreciate
    if you try to simplify your case to a minimal repro.

Minimal repro:

from abc import ABCMeta, abstractmethod
from typing import Generic, TypeVar, Union

A = TypeVar('A')


class Base(Generic[A]):
    __metaclass__ = ABCMeta

    @abstractmethod
    def do_stuff(self, a):
        # type: (A) -> None
        pass


class Foo(Generic[A], Base[A]):
    pass


class Bar(Generic[A], Base[A]):
    pass


class Baz(Foo[str], Bar[Union[str, int]]):
    def do_stuff(self, a):
        # type: (str) -> None
        return None
  • What is the actual behavior/output?

No error is reported

  • What is the behavior/output you expect?

The definition of Baz.do_stuff() accepts a str, which is incompatible with Bar.do_stuff()'s abstract method definition (which accepts Union[str, int]).

This bug appears to be related to the following TODO comment:

# TODO: What if some classes are generic?

Interestingly, if I reverse the order of Foo and Bar in Baz's base class list, mypy reports the error.

  • What are the versions of mypy and Python you are using?
    Do you see the same issue after installing mypy from Git master?

https://github.com/python/mypy/tree/103f5f3ec3fcc8fba429edcc4ee61c1370153ff9

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions