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

[WIP] Add PyTypeObject impl to PyRef #424

Closed
wants to merge 1 commit into from
Closed

Conversation

konstin
Copy link
Member

@konstin konstin commented Apr 1, 2019

As @DeflatedPickle noticed on gitter, there was no way to get the PyType from the associated type of a PyRef.

Open question: Do we want to add the following?

impl<T> AsPyRef<T> for T
where
    T: PyTypeInfo,
{
    #[inline]
    fn as_ref(&self, _py: Python) -> PyRef<T> {
        PyRef::from_ref(self)
    }
    #[inline]
    fn as_mut(&mut self, _py: Python) -> PyRefMut<T> {
        PyRefMut::from_mut(self)
    }
}

@@ -69,8 +68,8 @@ where
}

impl<'a, T: PyTypeInfo> PyRef<'a, T> {
pub(crate) fn from_ref(r: &'a T) -> Self {
PyRef(r, PhantomData)
pub fn from_ref(reference: &'a T) -> Self {
Copy link
Member

@kngwyu kngwyu Apr 1, 2019

Choose a reason for hiding this comment

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

I'm not for this change.
PyRef exists because we cannot always get *mut ffi::PyObject from &T whre T: PyTypeInfo.
But this change allows pyclass to use as_ptr without copying it to Python heap

@kngwyu
Copy link
Member

kngwyu commented Apr 1, 2019

Open question: Do we want to add the following?

I strongly disagree. It's unsafe and misleading.

I think get_type_from_object is OK but still can't imagine its concrete use cases.
So I think it's better to fix #381 first, and check the problem still remains or not.

@konstin konstin closed this Apr 9, 2019
@konstin
Copy link
Member Author

konstin commented Apr 9, 2019

I need to rethink this with a proper approach

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.

2 participants