[utils] Ensure `allow_types` for `variadic()` is a tuple
authordirkf <fieldhouse@gmx.net>
Sun, 19 Mar 2023 02:27:46 +0000 (02:27 +0000)
committerdirkf <fieldhouse@gmx.net>
Sun, 19 Mar 2023 02:29:00 +0000 (02:29 +0000)
test/test_utils.py
youtube_dl/utils.py

index ea2b96ed2a88a86b8700df9b5459ae127eb6e6b3..b85d397d05cfa3039bd0c02095071b5ac10ea5e0 100644 (file)
@@ -1563,6 +1563,7 @@ Line 1
         self.assertEqual(variadic(None), (None, ))
         self.assertEqual(variadic('spam'), ('spam', ))
         self.assertEqual(variadic('spam', allowed_types=dict), 'spam')
+        self.assertEqual(variadic('spam', allowed_types=[dict]), 'spam')
 
     def test_traverse_obj(self):
         _TEST_DATA = {
index 761edcd4962efd23f958b1c5af3ad8f21c7b0d46..f3c7af437868c493950034cc62532a11b682ec47 100644 (file)
@@ -4213,6 +4213,8 @@ def multipart_encode(data, boundary=None):
 
 
 def variadic(x, allowed_types=(compat_str, bytes, dict)):
+    if not isinstance(allowed_types, tuple) and isinstance(allowed_types, compat_collections_abc.Iterable):
+        allowed_types = tuple(allowed_types)
     return x if isinstance(x, compat_collections_abc.Iterable) and not isinstance(x, allowed_types) else (x,)