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_threading.py b/Lib/test/test_threading.py
index f44f17f..546773e 100644
--- a/Lib/test/test_threading.py
+++ b/Lib/test/test_threading.py
@@ -119,6 +119,13 @@ def func(): pass
thread = threading.Thread(target=func)
self.assertEqual(thread.name, "Thread-5 (func)")
+ @cpython_only
+ def test_disallow_instantiation(self):
+ # Ensure that the type disallows instantiation (bpo-43916)
+ lock = threading.Lock()
+ tp = type(lock)
+ self.assertRaises(TypeError, tp)
+
# Create a bunch of threads, let each do some work, wait until all are
# done.
def test_various_ops(self):