bpo-43916: Apply Py_TPFLAGS_DISALLOW_INSTANTIATION to selected types (GH-25748)
Apply Py_TPFLAGS_DISALLOW_INSTANTIATION to the following types:
* _dbm.dbm
* _gdbm.gdbm
* _multibytecodec.MultibyteCodec
* _sre..SRE_Scanner
* _thread._localdummy
* _thread.lock
* _winapi.Overlapped
* array.arrayiterator
* functools.KeyWrapper
* functools._lru_list_elem
* pyexpat.xmlparser
* re.Match
* re.Pattern
* unicodedata.UCD
* zlib.Compress
* zlib.Decompress
diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py
index 96d0cdb..e1b2c79 100644
--- a/Lib/test/test_re.py
+++ b/Lib/test/test_re.py
@@ -2215,6 +2215,15 @@ def test_signedness(self):
self.assertGreaterEqual(sre_compile.MAXREPEAT, 0)
self.assertGreaterEqual(sre_compile.MAXGROUPS, 0)
+ @cpython_only
+ def test_disallow_instantiation(self):
+ # Ensure that the type disallows instantiation (bpo-43916)
+ self.assertRaises(TypeError, re.Match)
+ self.assertRaises(TypeError, re.Pattern)
+ pat = re.compile("")
+ tp = type(pat.scanner(""))
+ self.assertRaises(TypeError, tp)
+
class ExternalTests(unittest.TestCase):