Skip to content

mypy base class compatibility #3

Closed
@jeremander

Description

@jeremander

There's some quirk in the definition of TextSerializable which causes mypy to error when inheriting from it along with some other base class.

Minimal example:

from fancy_dataclass.serialize import TextFileSerializable

class Mixin:
    pass

class A(TextFileSerializable):
    pass

class B(Mixin, TextFileSerializable):
    pass

Running mypy (version 1.14.1), I get:

error: Definition of "_from_bytes" in base class "TextSerializable" is incompatible with definition in base class "BinaryFileSerializable"  [misc]
error: Definition of "_to_bytes" in base class "TextSerializable" is incompatible with definition in base class "BinaryFileSerializable"  [misc]

The error only occurs on B, not A. My guess is that the type: ignore statement on TextFileSerializable (suppressing the error about incompatible method definitions) carries over to simple inheritance but not multiple inheritance.

Not sure if this is a bug in mypy or not, but ideally the method signatures could be fixed to be compatible.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions