Skip to content

Return type of "__eq__" incompatible with supertype "object" #2783

Closed
@zero323

Description

@zero323

Let's say I have a simple class intended for symbolical computations where == and != evaluate to another expression:

class Expr:
    def __eq__(self, other: object) -> 'Expr': ...
    def __ne__(self, other: object) -> 'Expr': ...
    def __add__(self, other: 'Expr') -> 'Expr': ...
    def __sub__(self, other: 'Expr') -> 'Expr': ...

This will result in following errors:

Return type of "__eq__" incompatible with supertype "object"
Return type of "__ne__" incompatible with supertype "object"

As far as I understand Python data model doesn't require rich comparison methods to return bool. Is it Mypy specific requirement or is there something wrong with my class definition?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions