Skip to content

Commit e719ce5

Browse files
committed
Adjust testing args for threading.Thread to allow any object with __iter__
1 parent 650ccde commit e719ce5

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

Lib/test/test_threading.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,21 +179,28 @@ def task(x):
179179
pass
180180

181181
invalid_args = (
182-
"test string",
183182
1,
184-
b"Bytes"
183+
3.14,
184+
None,
185+
object(),
185186
)
186187

187188
for args in invalid_args:
188189
with self.subTest(args=args):
189190
with self.assertRaises(TypeError):
190191
threading.Thread(target=task, args=args)
191192

192-
def test_lock_no_args(self):
193-
threading.Lock() # works
194-
self.assertRaises(TypeError, threading.Lock, 1)
195-
self.assertRaises(TypeError, threading.Lock, a=1)
196-
self.assertRaises(TypeError, threading.Lock, 1, 2, a=1, b=2)
193+
def test_args_valid_inputs_does_not_raise(self):
194+
def task():
195+
pass
196+
197+
class CustomIter:
198+
def __iter__(self):
199+
yield
200+
try:
201+
t = threading.Thread(target=task, args=CustomIter())
202+
except TypeError as e:
203+
self.fail(f"Thread raised an exception with an object that has the '__iter__' attribute with error {e}")
197204

198205
def test_lock_no_subclass(self):
199206
# Intentionally disallow subclasses of threading.Lock because they have

0 commit comments

Comments
 (0)