Clarify `#[pyclass(eq_int)]` docs
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.2k
- Forks
- 1k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 66
Description
Currently the eq_int parameter of #[pyclass] is described as the following:
This description is confusing to me. From my original interpretation, I was under the impression eq_int emitted the following pseudo-code:
# Without `eq_int`
def __eq__(self, other: MyEnum) -> bool:
return self == other
# With `eq_int`
def __eq__(self, other: MyEnum) -> bool:
return int(self) == int(other)
More specifically, I thought the eq_int attribute was purely an internal change that modifies how simple enums are compared, but did not have any user-facing effects. This was incorrect.
In reality, eq_int lets simple enums be compared with integers in addition to itself:
# What `eq_int` actually generates.
def __eq__(self, other: MyEnum | int) -> bool:
if isinstance(other, MyEnum):
return self == other
elif isinstance(other, int):
return int(self) == other
I think eq_int's description should be re-worded so the following are clear:
eq_intlets simple enums be compared for equality with integers in addition to itself- If the enum is also annotated with
#[pyclass(ord)], it also lets the type by compared as greater or lesser than integers __int__()returns the enum's discriminant, which is the same as runningMyEnum::Variant as u64in Rust
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with guide/pyclass-parameters.md at the linked #[pyclass] parameter description. Clarify that eq_int adds equality comparisons with integers, that #[pyclass(ord)] also enables ordering against integers, and that int returns the enum discriminant. Done when these user-facing effects are unambiguous in the documentation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, rust
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 1/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100