Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Py/PyAny: remove PartialEq impl and add is() #2183

Merged
merged 1 commit into from Feb 25, 2022
Merged

Conversation

birkenfeld
Copy link
Member

and fix the fallout, mostly in tests.

See #2175 (comment) for discussion.

@birkenfeld
Copy link
Member Author

The guide entry presumes #2175 as merged.

/// Returns whether the object is the same as the other.
///
/// This is equivalent to the Python expression `self is other`.
pub fn is<U: AsPyPointer>(&self, o: &U) -> bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this inherit the #[inline] attribute from the PartialEq method? (Similarly for the method on PyAny.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think probably makes sense for this to be #[inline].

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do

Copy link
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for updating migration notes too. It's a shame we can't deprecate trait implementations, however I would hope that any breaking changes users have to undergo are also removing possible bugs from their code 😄

/// Returns whether the object is the same as the other.
///
/// This is equivalent to the Python expression `self is other`.
pub fn is<U: AsPyPointer>(&self, o: &U) -> bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think probably makes sense for this to be #[inline].

@davidhewitt
Copy link
Member

Clippy fix needs rebasing on #2184

@birkenfeld
Copy link
Member Author

I actually found a semi-bug; you can see it in the tests (test_sequence and _pyproto), where vector of objects was compared directly to vec![1.into(),...].

It works since small integers are singletons in CPython, so I kept the logic the same for now, but that's not a guarantee and maybe should be changed to use eq.

@birkenfeld
Copy link
Member Author

BTW, a simple cargo test always results in

   Doc-tests pyo3
error[E0554]: `#![feature]` may not be used on the stable release channel
 --> /home/gbr/devel/pyo3/src/lib.rs:2:21
  |
2 | #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
  |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

for me now.

I can run with nightly, but then the UI tests usually fail, which is not pretty.

@mejrs
Copy link
Member

mejrs commented Feb 25, 2022

BTW, a simple cargo test always results in

Yeah I was getting annoyed by this too. It should be fixed with #2176

You can delete the rustdocflags in .cargo/config to get around it for now.

@davidhewitt
Copy link
Member

Looks great, I'm just going to hold off on merging this for a moment until #2175 is ready.

@davidhewitt davidhewitt mentioned this pull request Feb 25, 2022
src/types/any.rs Outdated Show resolved Hide resolved
and fix the fallout, mostly in tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants