cmp3

Minor Version:

Introduction

This project updates the concept of __cmp__ for python3.

Installation
Features
class cmp3.CmpABC()

This ABC can serve as a parent for classes using __cmp__.

__slots__ = ()
__cmp__(other: Any) -> Any

This abstract magic method is to be implemented in descendant classes returning a value that compares to 0 as self compares to other.

__eq__(other: Any) -> Any

This magic method is implemented as return self.__cmp__(other).__eq__(0).

__ge__(other: Any) -> Any

This magic method works analogous to __eq__.

__gt__(other: Any) -> Any

This magic method works analogous to __eq__.

__le__(other: Any) -> Any

This magic method works analogous to __eq__.

__lt__(other: Any) -> Any

This magic method works analogous to __eq__.

__ne__(other: Any) -> Any

This magic method works analogous to __eq__.

cmp3.cmp(x: Any, y: Any, /, *, mode: str = "portingguide") -> Any

This function returns a value that compares to 0 as x compares to y. If mode contains whitespace then it is split and tried sequentially until a submode is reached that does not raise an Exception.

The "magic" mode returns x.__cmp__(y).

The "eq" mode returns 0 if x == y else float("nan").

The "eq_strict" mode returns 0 if x == y else None.

The "le" mode utilizes x <= y and y <= x. It assumes that <= provides a partial order.

The "portingguide" mode uses the implementation of cmp that is recommended by the portingguide.

cmp3.cmpDeco(cls: type) -> type

This decorator writes the six rich comparison magic methods into cls. These magic methods are implemented just as described under CmpABC. Indeed, the decorator is used in the implementation of CmpABC.

cmp3.test() -> unittest.TextTestRunner
License
Impressum