Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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[:2] == (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
41 changes: 13 additions & 28 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 @@ -558,7 +557,7 @@ fn bpo_45315_workaround(py: Python<'_>, class_name: CString) {
}

/// Default new implementation
#[cfg(not(all(Py_3_10, not(PyPy))))]
#[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 @@ -567,29 +566,15 @@ unsafe extern "C" fn no_constructor_defined(
unsafe {
trampoline(|py| {
let tpobj = PyType::from_borrowed_type_ptr(py, subtype);
#[cfg(not(PyPy))]
{
// unlike `fully_qualified_name`, this always include the module
let module = tpobj
.module()
.map_or_else(|_| "<unknown>".into(), |s| s.to_string());
let qualname = tpobj.qualname();
let qualname = qualname.map_or_else(|_| "<unknown>".into(), |s| s.to_string());
Err(crate::exceptions::PyTypeError::new_err(format!(
"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"
)))
}
// unlike `fully_qualified_name`, this always include the module
let module = tpobj
.module()
.map_or_else(|_| "<unknown>".into(), |s| s.to_string());
let qualname = tpobj.qualname();
let qualname = qualname.map_or_else(|_| "<unknown>".into(), |s| s.to_string());
Err(crate::exceptions::PyTypeError::new_err(format!(
"cannot create '{module}.{qualname}' instances"
)))
})
}
}
Expand Down
Loading