Test implementation details of the re module.
"""
+ @cpython_only
+ def test_immutable(self):
+ # bpo-43908: check that re types are immutable
+ with self.assertRaises(TypeError):
+ re.Match.foo = 1
+ with self.assertRaises(TypeError):
+ re.Pattern.foo = 1
+ with self.assertRaises(TypeError):
+ pat = re.compile("")
+ tp = type(pat.scanner(""))
+ tp.foo = 1
+
def test_overlap_table(self):
f = sre_compile._generate_overlap_table
self.assertEqual(f(""), [])
.name = "re.Pattern",
.basicsize = sizeof(PatternObject),
.itemsize = sizeof(SRE_CODE),
- .flags = Py_TPFLAGS_DEFAULT,
+ .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE,
.slots = pattern_slots,
};
.name = "re.Match",
.basicsize = sizeof(MatchObject),
.itemsize = sizeof(Py_ssize_t),
- .flags = Py_TPFLAGS_DEFAULT,
+ .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE,
.slots = match_slots,
};
static PyType_Spec scanner_spec = {
.name = "_" SRE_MODULE ".SRE_Scanner",
.basicsize = sizeof(ScannerObject),
- .flags = Py_TPFLAGS_DEFAULT,
+ .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE,
.slots = scanner_slots,
};