Skip to content

What is the best way to compare two objects within a PyIterator (PyAny) #2502

Answered by davidhewitt
tgross35 asked this question in Questions
Discussion options

You must be logged in to vote

implement PartialEq by unwrapping the eq and ne methods on PyAny,

You probably want to wrap your PyAny objects in a newtype which does exactly this, or alternatively could return None from PartialEq::cmp if there's an exception raised during comparison. For now we're undecided what the correct error handling strategy is if PyO3 were to provide a PartialEq implementation.

Some brief history - PyAny used to implement PartialEq using pointer comparison (i.e. Python is), which was almost certainly a footgun. We removed that implementation a couple of versions ago, and now in a cooling off period to take stock before we consider if we add a more correct implementation back.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@tgross35
Comment options

@davidhewitt
Comment options

Answer selected by tgross35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants