Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pytests/tests/test_pyclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ def __new__(cls):


@pytest.mark.xfail(
platform.python_implementation() == "PyPy" and sys.version_info < (3, 11),
reason="broken on older PyPy due to https://github.com/pypy/pypy/issues/5319 on supported PyPy",
platform.python_implementation() == "PyPy" and sys.version_info == (3, 11),
reason="broken on PyPy 3.11 due to https://github.com/pypy/pypy/issues/5319, waiting for next release",
)
@pytest.mark.parametrize(
"cls, exc_message",
Expand Down
24 changes: 7 additions & 17 deletions src/pyclass/create_type_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,14 +437,13 @@ impl PyTypeBuilder {
unsafe { self.push_slot(ffi::Py_tp_base, self.tp_base) }

if !self.has_new {
// PyPy doesn't respect the flag
// https://github.com/pypy/pypy/issues/5318
#[cfg(not(all(Py_3_10, not(PyPy))))]
// Flag introduced in 3.10, only worked in PyPy on 3.11
#[cfg(not(any(all(Py_3_10, not(PyPy)), all(Py_3_11, PyPy))))]
{
// Safety: This is the correct slot type for Py_tp_new
unsafe { self.push_slot(ffi::Py_tp_new, no_constructor_defined as *mut c_void) }
}
#[cfg(all(Py_3_10, not(PyPy)))]
#[cfg(any(all(Py_3_10, not(PyPy)), all(Py_3_11, PyPy)))]
{
self.class_flags |= ffi::Py_TPFLAGS_DISALLOW_INSTANTIATION;
}
Expand Down Expand Up @@ -557,8 +556,9 @@ fn bpo_45315_workaround(py: Python<'_>, class_name: CString) {
std::mem::forget(class_name);
}

/// Default new implementation
#[cfg(not(all(Py_3_10, not(PyPy))))]
/// Default new implementation, to match
/// <https://github.com/python/cpython/blob/3663b2ad54c9e15775a605facf69da8f5ee8d335/Objects/typeobject.c#L2427-L2428>
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if this comment still makes sense. I guess the output should be identical still..


Also I think the #[cfg(not(PyPy))] in the trampoline below needs to go now, because PyPy does the same thing as CPython now, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for catching, sorry for my shoddy patch 😂

#[cfg(not(any(all(Py_3_10, not(PyPy)), all(Py_3_11, PyPy))))]
unsafe extern "C" fn no_constructor_defined(
subtype: *mut ffi::PyTypeObject,
_args: *mut ffi::PyObject,
Expand All @@ -579,19 +579,9 @@ unsafe extern "C" fn no_constructor_defined(
"cannot create '{module}.{qualname}' instances"
)))
}
#[cfg(PyPy)]
{
// https://github.com/pypy/pypy/issues/5319
// .qualname() seems wrong on PyPy, includes the module already
let full_name = tpobj
.qualname()
.map_or_else(|_| "<unknown>".into(), |s| s.to_string());
Err(crate::exceptions::PyTypeError::new_err(format!(
"cannot create '{full_name}' instances"
)))
}
})
}
ptr::null_mut()
}

unsafe extern "C" fn call_super_clear(slf: *mut ffi::PyObject) -> c_int {
Expand Down
Loading