File tree Expand file tree Collapse file tree 3 files changed +24
-1
lines changed
Misc/NEWS.d/next/Core and Builtins Expand file tree Collapse file tree 3 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -346,6 +346,25 @@ def test_repeated_attribute_pops(self):
346
346
347
347
# frozen and namespace module reprs are tested in importlib.
348
348
349
+ def test_subclass_with_slots (self ):
350
+ # In 3.11alpha this crashed, as the slots weren't NULLed.
351
+
352
+ class ModuleWithSlots (ModuleType ):
353
+ __slots__ = ("a" , "b" )
354
+
355
+ def __init__ (self , name ):
356
+ super ().__init__ (name )
357
+
358
+ m = ModuleWithSlots ("name" )
359
+ with self .assertRaises (AttributeError ):
360
+ m .a
361
+ with self .assertRaises (AttributeError ):
362
+ m .b
363
+ m .a , m .b = 1 , 2
364
+ self .assertEqual (m .a , 1 )
365
+ self .assertEqual (m .b , 2 )
366
+
367
+
349
368
350
369
if __name__ == '__main__' :
351
370
unittest .main ()
Original file line number Diff line number Diff line change
1
+ Fix bug introduced during 3.11alpha where subclasses of ``types.ModuleType ``
2
+ with ``__slots__ `` were not initialized correctly, resulting in an
3
+ interpreter crash.
Original file line number Diff line number Diff line change 4
4
#include "Python.h"
5
5
#include "pycore_call.h" // _PyObject_CallNoArgs()
6
6
#include "pycore_interp.h" // PyInterpreterState.importlib
7
+ #include "pycore_object.h" // _PyType_AllocNoTrack
7
8
#include "pycore_pystate.h" // _PyInterpreterState_GET()
8
9
#include "pycore_moduleobject.h" // _PyModule_GetDef()
9
10
#include "structmember.h" // PyMemberDef
@@ -80,7 +81,7 @@ static PyModuleObject *
80
81
new_module_notrack (PyTypeObject * mt )
81
82
{
82
83
PyModuleObject * m ;
83
- m = PyObject_GC_New (PyModuleObject , mt );
84
+ m = (PyModuleObject * ) _PyType_AllocNoTrack ( mt , 0 );
84
85
if (m == NULL )
85
86
return NULL ;
86
87
m -> md_def = NULL ;
You can’t perform that action at this time.
0 commit comments