-
Notifications
You must be signed in to change notification settings - Fork 219
Closed
astral-sh/ruff
#23100Milestone
Description
I have a Money class where I want to support comparisons with literal zero as a shorthand (e.g., money > 0) so I've defined overloads like this:
from typing import Literal, Union, overload class Money: @overload def __gt__(self, other: "Money") -> bool: ... @overload def __gt__(self, other: Literal[0]) -> bool: ... def __gt__(self, other: Union["Money", Literal[0]]) -> bool: ...When I try to test it:
positive_money` = Money(100) assert positive_money > 0ty reports:
error[unsupported-operator]: Unsupported `>` operation --> tests/utils/test_money.py:285:16 | 283 | negative_money = Money(-50) 284 | 285 | assert positive_money > 0 | --------------^^^- | | | | | Has type `Literal[0]` | Has type `Money` 286 | assert not (zero_money > 0) 287 | assert not (negative_money > 0) | info: rule `unsupported-operator` is enabled by defaultI've confirmed this pattern works fine with mypy. Is this an explicitly "implementation skipped" behavior?
Thank you for all the work on ty!
Originally posted by @flpStrri in ruff#15383
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels