-
Notifications
You must be signed in to change notification settings - Fork 784
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
feature gate PyCell
#4177
Conversation
src/type_object.rs
Outdated
unsafe impl<T> HasPyGilRef for T | ||
where | ||
T: PyNativeType, | ||
{ | ||
type AsRefTarget = Self; | ||
} | ||
|
||
#[cfg(not(feature = "gil-refs"))] | ||
unsafe impl<T> HasPyGilRef for T {} | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 🙃
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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
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>"), | ||
} | ||
}) |
There was a problem hiding this comment.
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
...
There was a problem hiding this comment.
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 👍
Part of #3960
This moves the deprecated
PyCell
and its accompanying APIs behind thegil-refs
feature gate.pyo3-macros-backend
PyNativeType
feature gateHasPyGilRef::AsRefTarget
(the trait can be fully removed once thegil-refs
feature is gone)HasPyGilRef
PyCell