8000 Mypy shows the error for operators provided via functools.total_ordering decorator · Issue #4624 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Mypy shows the error for operators provided via functools.total_ordering decorator #4624

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
konradhalas opened this issue Feb 23, 2018 · 1 comment

Comments

@konradhalas
Copy link

Mypy shows the error of an unsupported comparison operator for classes with @functools.total_ordering decorator and with implemented == and <.

Example:

import decimal
import functools
import typing


@functools.total_ordering
class Money:

    def __init__(self, amount: str) -> None:
        self.amount = decimal.Decimal(amount)

    def __eq__(self, other: typing.Any) -> bool:
        if isinstance(other, Money):
            return self.amount == other.amount
        return NotImplemented

    def __lt__(self, other: typing.Any) -> bool:
        if isinstance(other, Money):
            return self.amount < other.amount
        return NotImplemented


assert Money('10.00') <= Money('10.00')

Mypy output (--strict flag is enabled):

money.py:23: error: Unsupported left operand type for <= ("Money")

My configuration:

  • Python 3.6.4
  • mypy 0.570-dev-3545a71ba11576b08007f70d8407bf7924738886

If it's typeshed related issue, please close it and I will post it there.

@ilevkivskyi
Copy link
Member

Duplicate of #4610

@ilevkivskyi ilevkivskyi marked this as a duplicate of #4610 Feb 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0