Skip to content

Incompatible definition of methods reported when using multiple inheritance #9319

Closed
@frerich

Description

@frerich

Using mypy 0.782, errors about incompatible method redefinitions are issued -- but only if multiple inheritance is in play.

How to Reproduce

Run mypy (without any arguments) on this script:

import enum

class C:
    pass

class D(C, enum.IntFlag):
    pass

Expected behaviour

mypy should print

Success: no issues found in 1 source file

Actual behaviour

mypy prints three error messages:

mypy-error.py:6: error: Definition of "__xor__" in base class "int" is incompatible with definition in base class "Flag"
mypy-error.py:6: error: Definition of "__or__" in base class "int" is incompatible with definition in base class "Flag"
mypy-error.py:6: error: Definition of "__and__" in base class "int" is incompatible with definition in base class "Flag"
Found 3 errors in 1 file (checked 1 source file)

Comments

The error messages go away when

  • Not using multiple inheritance, i.e. class D(enum.IntFlag) instead of class D(C, enum.IntFlag).
  • Or: when using enum.Flag instead of enum.IntFlag

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongfalse-positivemypy gave an error on correct code

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions