mirror of
https://github.com/python/cpython.git
synced 2025-08-24 02:35:59 +00:00
gh-114315: Make threading.Lock
a real class, not a factory function (#114479)
`threading.Lock` is now the underlying class and is constructable rather than the old factory function. This allows for type annotations to refer to it which had no non-ugly way to be expressed prior to this. --------- Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com> Co-authored-by: Gregory P. Smith <greg@krypto.org>
This commit is contained in:
parent
b52fc70d1a
commit
d96358ff9d
5 changed files with 52 additions and 14 deletions
|
@ -171,11 +171,21 @@ class ThreadTests(BaseTestCase):
|
|||
t.start()
|
||||
t.join()
|
||||
|
||||
@cpython_only
|
||||
def test_disallow_instantiation(self):
|
||||
# Ensure that the type disallows instantiation (bpo-43916)
|
||||
lock = threading.Lock()
|
||||
test.support.check_disallow_instantiation(self, type(lock))
|
||||
def test_lock_no_args(self):
|
||||
threading.Lock() # works
|
||||
self.assertRaises(TypeError, threading.Lock, 1)
|
||||
self.assertRaises(TypeError, threading.Lock, a=1)
|
||||
self.assertRaises(TypeError, threading.Lock, 1, 2, a=1, b=2)
|
||||
|
||||
def test_lock_no_subclass(self):
|
||||
# Intentionally disallow subclasses of threading.Lock because they have
|
||||
# never been allowed, so why start now just because the type is public?
|
||||
with self.assertRaises(TypeError):
|
||||
class MyLock(threading.Lock): pass
|
||||
|
||||
def test_lock_or_none(self):
|
||||
import types
|
||||
self.assertIsInstance(threading.Lock | None, types.UnionType)
|
||||
|
||||
# Create a bunch of threads, let each do some work, wait until all are
|
||||
# done.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue