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_zlib.py b/Lib/test/test_zlib.py
index 7f30cac..694ef6e 100644
--- a/Lib/test/test_zlib.py
+++ b/Lib/test/test_zlib.py
@@ -129,6 +129,14 @@ def test_overflow(self):
with self.assertRaisesRegex(OverflowError, 'int too large'):
zlib.decompressobj().flush(sys.maxsize + 1)
+ @support.cpython_only
+ def test_disallow_instantiation(self):
+ # Ensure that the type disallows instantiation (bpo-43916)
+ comp_type = type(zlib.compressobj())
+ decomp_type = type(zlib.decompressobj())
+ self.assertRaises(TypeError, comp_type)
+ self.assertRaises(TypeError, decomp_type)
+
class BaseCompressTestCase(object):
def check_big_compress_buffer(self, size, compress_func):