@@ -437,14 +437,13 @@ impl PyTypeBuilder {
437
437
unsafe { self . push_slot ( ffi:: Py_tp_base , self . tp_base ) }
438
438
439
439
if !self . has_new {
440
- // PyPy doesn't respect the flag
441
- // https://github.com/pypy/pypy/issues/5318
442
- #[ cfg( not( all( Py_3_10 , not( PyPy ) ) ) ) ]
440
+ // Flag introduced in 3.10, only worked in PyPy on 3.11
441
+ #[ cfg( not( any( all( Py_3_10 , not( PyPy ) ) , all( Py_3_11 , PyPy ) ) ) ) ]
443
442
{
444
443
// Safety: This is the correct slot type for Py_tp_new
445
444
unsafe { self . push_slot ( ffi:: Py_tp_new , no_constructor_defined as * mut c_void ) }
446
445
}
447
- #[ cfg( all( Py_3_10 , not( PyPy ) ) ) ]
446
+ #[ cfg( any ( all( Py_3_10 , not( PyPy ) ) , all ( Py_3_11 , PyPy ) ) ) ]
448
447
{
449
448
self . class_flags |= ffi:: Py_TPFLAGS_DISALLOW_INSTANTIATION ;
450
449
}
@@ -558,7 +557,7 @@ fn bpo_45315_workaround(py: Python<'_>, class_name: CString) {
558
557
}
559
558
560
559
/// Default new implementation
561
- #[ cfg( not( all( Py_3_10 , not( PyPy ) ) ) ) ]
560
+ #[ cfg( not( any ( all( Py_3_10 , not( PyPy ) ) , all ( Py_3_11 , PyPy ) ) ) ) ]
562
561
unsafe extern "C" fn no_constructor_defined (
563
562
subtype : * mut ffi:: PyTypeObject ,
564
563
_args : * mut ffi:: PyObject ,
@@ -567,29 +566,15 @@ unsafe extern "C" fn no_constructor_defined(
567
566
unsafe {
568
567
trampoline ( |py| {
569
568
let tpobj = PyType :: from_borrowed_type_ptr ( py, subtype) ;
570
- #[ cfg( not( PyPy ) ) ]
571
- {
572
- // unlike `fully_qualified_name`, this always include the module
573
- let module = tpobj
574
- . module ( )
575
- . map_or_else ( |_| "<unknown>" . into ( ) , |s| s. to_string ( ) ) ;
576
- let qualname = tpobj. qualname ( ) ;
577
- let qualname = qualname. map_or_else ( |_| "<unknown>" . into ( ) , |s| s. to_string ( ) ) ;
578
- Err ( crate :: exceptions:: PyTypeError :: new_err ( format ! (
579
- "cannot create '{module}.{qualname}' instances"
580
- ) ) )
581
- }
582
- #[ cfg( PyPy ) ]
583
- {
584
- // https://github.com/pypy/pypy/issues/5319
585
- // .qualname() seems wrong on PyPy, includes the module already
586
- let full_name = tpobj
587
- . qualname ( )
588
- . map_or_else ( |_| "<unknown>" . into ( ) , |s| s. to_string ( ) ) ;
589
- Err ( crate :: exceptions:: PyTypeError :: new_err ( format ! (
590
- "cannot create '{full_name}' instances"
591
- ) ) )
592
- }
569
+ // unlike `fully_qualified_name`, this always include the module
570
+ let module = tpobj
571
+ . module ( )
572
+ . map_or_else ( |_| "<unknown>" . into ( ) , |s| s. to_string ( ) ) ;
573
+ let qualname = tpobj. qualname ( ) ;
574
+ let qualname = qualname. map_or_else ( |_| "<unknown>" . into ( ) , |s| s. to_string ( ) ) ;
575
+ Err ( crate :: exceptions:: PyTypeError :: new_err ( format ! (
576
+ "cannot create '{module}.{qualname}' instances"
577
+ ) ) )
593
578
} )
594
579
}
595
580
}
0 commit comments