File tree 3 files changed +17
-3
lines changed
Misc/NEWS.d/next/Core and Builtins
3 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -2190,6 +2190,18 @@ class ImplementationTest(unittest.TestCase):
2190
2190
Test implementation details of the re module.
2191
2191
"""
2192
2192
2193
+ @cpython_only
2194
+ def test_immutable (self ):
2195
+ # bpo-43908: check that re types are immutable
2196
+ with self .assertRaises (TypeError ):
2197
+ re .Match .foo = 1
2198
+ with self .assertRaises (TypeError ):
2199
+ re .Pattern .foo = 1
2200
+ with self .assertRaises (TypeError ):
2201
+ pat = re .compile ("" )
2202
+ tp = type (pat .scanner ("" ))
2203
+ tp .foo = 1
2204
+
2193
2205
def test_overlap_table (self ):
2194
2206
f = sre_compile ._generate_overlap_table
2195
2207
self .assertEqual (f ("" ), [])
Original file line number Diff line number Diff line change
1
+ Make :mod: `re ` types immutable. Patch by
2
+ Erlend E. Aasland.
Original file line number Diff line number Diff line change @@ -2690,7 +2690,7 @@ static PyType_Spec pattern_spec = {
2690
2690
.name = "re.Pattern" ,
2691
2691
.basicsize = sizeof (PatternObject ),
2692
2692
.itemsize = sizeof (SRE_CODE ),
2693
- .flags = Py_TPFLAGS_DEFAULT ,
2693
+ .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE ,
2694
2694
.slots = pattern_slots ,
2695
2695
};
2696
2696
@@ -2755,7 +2755,7 @@ static PyType_Spec match_spec = {
2755
2755
.name = "re.Match" ,
2756
2756
.basicsize = sizeof (MatchObject ),
2757
2757
.itemsize = sizeof (Py_ssize_t ),
2758
- .flags = Py_TPFLAGS_DEFAULT ,
2758
+ .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE ,
2759
2759
.slots = match_slots ,
2760
2760
};
2761
2761
@@ -2781,7 +2781,7 @@ static PyType_Slot scanner_slots[] = {
2781
2781
static PyType_Spec scanner_spec = {
2782
2782
.name = "_" SRE_MODULE ".SRE_Scanner" ,
2783
2783
.basicsize = sizeof (ScannerObject ),
2784
- .flags = Py_TPFLAGS_DEFAULT ,
2784
+ .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE ,
2785
2785
.slots = scanner_slots ,
2786
2786
};
2787
2787
You can’t perform that action at this time.
0 commit comments