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

feature gate PyCell #4177

Merged
merged 3 commits into from May 12, 2024
Merged

feature gate PyCell #4177

merged 3 commits into from May 12, 2024

Conversation

Icxolu
Copy link
Contributor

@Icxolu Icxolu commented May 11, 2024

Part of #3960

This moves the deprecated PyCell and its accompanying APIs behind the gil-refs feature gate.

  • thread feature gate into pyo3-macros-backend
  • feature gate PyNativeType
  • feature gate HasPyGilRef::AsRefTarget (the trait can be fully removed once the gil-refs feature is gone)
  • feature gate HasPyGilRef
  • feature gate PyCell

@Icxolu Icxolu added the CI-skip-changelog Skip checking changelog entry label May 11, 2024
unsafe impl<T> HasPyGilRef for T
where
T: PyNativeType,
{
type AsRefTarget = Self;
}

#[cfg(not(feature = "gil-refs"))]
unsafe impl<T> HasPyGilRef for T {}

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, is this right? Does it cause any soundness issues if its implemented for everything?

Copy link
Contributor Author

@Icxolu Icxolu May 11, 2024

Choose a reason for hiding this comment

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

The idea was, that implementing it for everything should be functionally equivalent to removing the requirement. There are no APIs left (at least I could find any) that have HasPyGilRef as a direct bound without gil-refs. So this blanket is only there to satisfy the requirement for PyTypeCheck and PyTypeInfo, which currently use it as a supertrait.

But someone please double check that this has no other implication 🙃

Copy link
Member

Choose a reason for hiding this comment

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

So is this temporary, i.e. will we feature-gate the whole trait and its usage as a super trait later on?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was thinking temporary until we fully remove the gil-refs in 0.23, at which point we can also remove the trait and the supertrait requirement.

Copy link
Member

Choose a reason for hiding this comment

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

Couldn't we already feature gate the trait (and bounds) in 0.22 based on the feature?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think all the bounds are already gated. We could also gate the whole trait, but then we have to duplicate the definitions of PyTypeCheck and PyTypeInfo to conditionally include the supertrait. (Or we could could introduce a helper trait in the middle to bridge, but I think that is more or less I've done here, just with a different name)

Copy link
Member

Choose a reason for hiding this comment

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

We could also gate the whole trait, but then we have to duplicate the definitions of PyTypeCheck and PyTypeInfo to conditionally include the supertrait.

I think I would prefer that (we could use a small local helper macro like we had for the const thread_local! syntax. Personally, I would find that less weird than the universal trait impl. I do see any unintended side effects though, so this appears to be purely a matter of preference to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure thing, PyTypeCheck and PyTypeInfo are actually not that big, so introducing a macro for them is maybe a bit overkill and maybe having them duplicated until 0.22 is out is not such big of a deal.

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.

Great to see this progress, thanks!

I think the semver-checks job wants us to bump the Cargo.toml package version to 0.22.0-dev. I'm surprised that it didn't notice any changes before 🤔

src/instance.rs Outdated
Comment on lines 1880 to 1892
Python::with_gil(|py| {
use crate::types::PyAnyMethods;
let obj = self.bind(py).as_any();
match obj.str() {
Ok(s) => return f.write_str(&s.to_string_lossy()),
Err(err) => err.write_unraisable_bound(py, Some(obj)),
}

match obj.get_type().name() {
Ok(name) => write!(f, "<unprintable {} object>", name),
Err(_err) => f.write_str("<unprintable object>"),
}
})
Copy link
Member

Choose a reason for hiding this comment

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

Did this implementation need expanding? It looks like it already went through Bound...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, good catch, we can just drop the AsRefTarget bound 👍

@alex alex added this pull request to the merge queue May 12, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks May 12, 2024
@alex alex added this pull request to the merge queue May 12, 2024
Merged via the queue into PyO3:main with commit 10152a7 May 12, 2024
43 checks passed
@Icxolu Icxolu deleted the deprecate/pycell branch May 12, 2024 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI-skip-changelog Skip checking changelog entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants