Ordering enumeration and protocols.
Python 3.8 or above is required.
Installing the library with pip
is quite simple:
$ pip install orderings
Alternatively, the library can be installed from source:
$ git clone https://github.com/nekitdev/orderings.git
$ cd orderings
$ python -m pip install .
You can add orderings
as a dependency with the following command:
$ poetry add orderings
Or by directly specifying it in the configuration like so:
[tool.poetry.dependencies]
orderings = "^1.4.0"
Alternatively, you can add it directly from the source:
[tool.poetry.dependencies.orderings]
git = "https://github.com/nekitdev/orderings.git"
Sometimes it's simpler to handle ordering in one method, for example when comparing iterators;
then it's trivial to implement the regular ordering methods using the compare
method.
The core of orderings
is the Ordering
enumeration
and the Compare
protocol:
from typing import Generic, TypeVar
from attrs import frozen
from orderings import Compare, Ordering, StrictOrdered
from typing_extensions import Self
T = TypeVar("T", bound=StrictOrdered)
@frozen()
class Wrap(Compare, Generic[T]):
value: T
def compare(self, other: Self) -> Ordering:
self_value = self.value
other_value = other.value
if self_value < other_value:
return Ordering.LESS
if self_value > other_value:
return Ordering.GREATER
return Ordering.EQUAL
Compare
implements all ordering operations
(==
, !=
, <
, >
, <=
, >=
) using the compare
method.
You can find the documentation here.
If you need support with the library, you can send an email or refer to the official Discord server.
You can find the changelog here.
You can find the Security Policy of orderings
here.
If you are interested in contributing to orderings
, make sure to take a look at the
Contributing Guide, as well as the Code of Conduct.
orderings
is licensed under the MIT License terms. See License for details.