]> jfr.im git - yt-dlp.git/commitdiff
[compat] Ensure submodules are imported correctly
authorpukkandan <redacted>
Sat, 22 Jul 2023 12:26:53 +0000 (17:56 +0530)
committerpukkandan <redacted>
Sat, 22 Jul 2023 12:40:35 +0000 (18:10 +0530)
Closes #7663

test/test_compat.py
yt_dlp/compat/__init__.py
yt_dlp/compat/_deprecated.py
yt_dlp/compat/urllib/__init__.py
yt_dlp/utils/__init__.py

index 003a97abf73f468af9c49874eefbfd60399d4954..71ca7f99f10c50d28817d2959b673feb5ae88cf8 100644 (file)
@@ -9,15 +9,16 @@
 
 
 import struct
-import urllib.parse
 
 from yt_dlp import compat
+from yt_dlp.compat import urllib  # isort: split
 from yt_dlp.compat import (
     compat_etree_fromstring,
     compat_expanduser,
     compat_urllib_parse_unquote,
     compat_urllib_parse_urlencode,
 )
+from yt_dlp.compat.urllib.request import getproxies
 
 
 class TestCompat(unittest.TestCase):
@@ -28,8 +29,7 @@ def test_compat_passthrough(self):
         with self.assertWarns(DeprecationWarning):
             compat.WINDOWS_VT_MODE
 
-        # TODO: Test submodule
-        # compat.asyncio.events  # Must not raise error
+        self.assertEqual(urllib.request.getproxies, getproxies)
 
         with self.assertWarns(DeprecationWarning):
             compat.compat_pycrypto_AES  # Must not raise error
index a41a80ebb6c9c1add04661f2d0734bc961a161a5..832a9138d39d0b7ab1451ec3db9b89f140bb41a4 100644 (file)
@@ -1,14 +1,11 @@
 import os
 import sys
-import warnings
 import xml.etree.ElementTree as etree
 
-from ._deprecated import *  # noqa: F401, F403
 from .compat_utils import passthrough_module
 
-# XXX: Implement this the same way as other DeprecationWarnings without circular import
-passthrough_module(__name__, '._legacy', callback=lambda attr: warnings.warn(
-    DeprecationWarning(f'{__name__}.{attr} is deprecated'), stacklevel=5))
+passthrough_module(__name__, '._deprecated')
+del passthrough_module
 
 
 # HTMLParseError has been deprecated in Python 3.3 and removed in
index 14d37b236725bebe5225ae729b7fde02b1935317..607bae99999d98ddbc6826219c190585de1707d6 100644 (file)
@@ -1,4 +1,12 @@
 """Deprecated - New code should avoid these"""
+import warnings
+
+from .compat_utils import passthrough_module
+
+# XXX: Implement this the same way as other DeprecationWarnings without circular import
+passthrough_module(__name__, '.._legacy', callback=lambda attr: warnings.warn(
+    DeprecationWarning(f'{__name__}.{attr} is deprecated'), stacklevel=6))
+del passthrough_module
 
 import base64
 import urllib.error
index 6b6b8e103df300aa8d718de519cb9249834cec54..b27cc6133c44cd046892251ea0279f459cb2ba9a 100644 (file)
@@ -1,6 +1,9 @@
 # flake8: noqa: F405
 from urllib import *  # noqa: F403
 
+del request
+from . import request  # noqa: F401
+
 from ..compat_utils import passthrough_module
 
 passthrough_module(__name__, 'urllib')
index 0b00adddb4e8be03cf8b30744836dcd5a7a70536..c267e326f0642d71bafb772fd80e970d2f96bffa 100644 (file)
@@ -1,6 +1,4 @@
-# flake8: noqa: F401, F403
-import warnings
-
+# flake8: noqa: F403
 from ..compat.compat_utils import passthrough_module
 
 passthrough_module(__name__, '._deprecated')
@@ -9,4 +7,4 @@
 # isort: off
 from .traversal import *
 from ._utils import *
-from ._utils import _configuration_args, _get_exe_version_output
+from ._utils import _configuration_args, _get_exe_version_output  # noqa: F401