pyo3/pytests
bors[bot] dbf7b233aa
Merge #3203
3203: support ordering magic methods for `#[pyclass]` r=adamreichold a=davidhewitt

Closes #2089 

This adds `__lt__`, `__le__`, `__eq__`, `__ne__`, `__gt__`, and `__ge__` as per the Python implementations of what we call `__richcmp__`.

There's a UI test confirming that the user cannot implement split forms and `__richcmp__` simultaneously.

There's also a benchmark comparing implementing these split methods against using `__richcmp__`. I couldn't see a meaningful performance difference, so I'm tempted to deprecate `__richcmp__`, given that's not a magic method which exists in Python. Potentially we can provide options such as the opt-in `#[pyclass(eq, ord)]` to avoid boilerplate for people who don't want to implement six different methods.



Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2023-06-05 07:13:23 +00:00
..
pyo3_pytests pytests: merge benchmark and test crates 2022-02-05 10:16:46 +00:00
src Merge #3203 2023-06-05 07:13:23 +00:00
tests support ordering magic methods for `#[pyclass]` 2023-06-04 13:58:18 +01:00
Cargo.toml Add `publish = false` to pyo3-ffi-check and pytests crate 2022-12-03 21:12:54 +08:00
MANIFEST.in pytests: merge benchmark and test crates 2022-02-05 10:16:46 +00:00
README.md pytests: merge benchmark and test crates 2022-02-05 10:16:46 +00:00
build.rs pytests: merge benchmark and test crates 2022-02-05 10:16:46 +00:00
noxfile.py add `#[pyo3(signature = (...))]` attribute (#2702) 2022-10-25 07:23:21 +01:00
pyproject.toml examples: update maturin to 0.13 2022-08-18 08:17:53 +01:00
requirements-dev.txt support ordering magic methods for `#[pyclass]` 2023-06-04 13:58:18 +01:00

README.md

pyo3-pytests

An extension module built using PyO3, used to test and benchmark PyO3 from Python.

Testing

This package is intended to be built using maturin. Once built, you can run the tests using pytest:

pip install maturin
maturin develop
pytest

Alternatively, install nox and run the tests inside an isolated environment:

nox

Running benchmarks

You can install the module in your Python environment and then run the benchmarks with pytest:

pip install .
pytest --benchmark-enable

Or with nox:

nox -s bench