Repository: yt-dlp/yt-dlp
File: yt_dlp/networking/common.py (Python)

Code before:
            # for one handler in which such protocol (and proxy) is not supported by another handler.
            if self._SUPPORTED_URL_SCHEMES is not None and proxy_key not in (*self._SUPPORTED_URL_SCHEMES, 'all'):
                continue

            if self._SUPPORTED_PROXY_SCHEMES is None:
                # Skip proxy scheme checks
                continue

            # Scheme-less proxies are not supported
            if urllib.request._parse_proxy(proxy_url)[0] is None:
                raise UnsupportedRequest(f'Proxy "{proxy_url}" missing scheme')

            scheme = urllib.parse.urlparse(proxy_url).scheme.lower()
            if scheme not in self._SUPPORTED_PROXY_SCHEMES:
                raise UnsupportedRequest(f'Unsupported proxy type: "{scheme}"')

    def _check_timeout_extension(self, extensions):
        if not isinstance(extensions.pop('timeout', None), (float, int, type(None))):
            raise TypeError('timeout extension is not a float or int')

    def _check_cookiejar_extension(self, extensions):
        if not isinstance(extensions.pop('cookiejar', None), (CookieJar, type(None))):
            raise TypeError('cookiejar extension is not a CookieJar')

    def _check_extensions(self, extensions):
        """Check extensions for unsupported extensions. To be implemented by subclasses."""

    def _validate(self, request):
        self._check_url_scheme(request)
        self._check_proxies(request.proxies or self.proxies)
        extensions = request.extensions.copy()
        self._check_extensions(extensions)
        if extensions:
            # XXX: add support for optional extensions
            raise UnsupportedRequest(f'Unsupported extensions: {", ".join(extensions.keys())}')

    @wrap_request_errors
    def validate(self, request: Request):
        if not isinstance(request, Request):
            raise TypeError('Expected an instance of Request')
        self._validate(request)

    @wrap_request_errors
    def send(self, request: Request) -> Response:
        if not isinstance(request, Request):
            raise TypeError('Expected an instance of Request')
        return self._send(request)

    @abc.abstractmethod
    def _send(self, request: Request):
        """Handle a request from start to finish. Redefine in subclasses."""

Review comment (suggestion):
I'd do this (+other comment) since type checking isn't really dependant on whether the RH actually supports it or not. But I won't insist.
```py
from types import NoneType

    def _check_extensions(self, extensions):
        """Check extensions for unsupported extensions. To be implemented by subclasses."""
        assert isinstance(extensions.get('cookiejar'), (CookieJar, NoneType))
        assert isinstance(extensions.get('timeout'), (float, int, NoneType))
```

Code after:
            # This is to allow a case where a proxy may be set for a protocol
            # for one handler in which such protocol (and proxy) is not supported by another handler.
            if self._SUPPORTED_URL_SCHEMES is not None and proxy_key not in (*self._SUPPORTED_URL_SCHEMES, 'all'):
                continue

            if self._SUPPORTED_PROXY_SCHEMES is None:
                # Skip proxy scheme checks
                continue

            # Scheme-less proxies are not supported
            if urllib.request._parse_proxy(proxy_url)[0] is None:
                raise UnsupportedRequest(f'Proxy "{proxy_url}" missing scheme')

            scheme = urllib.parse.urlparse(proxy_url).scheme.lower()
            if scheme not in self._SUPPORTED_PROXY_SCHEMES:
                raise UnsupportedRequest(f'Unsupported proxy type: "{scheme}"')

    def _check_extensions(self, extensions):
        """Check extensions for unsupported extensions. Subclasses should extend this."""
        assert isinstance(extensions.get('cookiejar'), (CookieJar, NoneType))
        assert isinstance(extensions.get('timeout'), (float, int, NoneType))

    def _validate(self, request):
        self._check_url_scheme(request)
        self._check_proxies(request.proxies or self.proxies)
        extensions = request.extensions.copy()
        self._check_extensions(extensions)
        if extensions:
            # TODO: add support for optional extensions
            raise UnsupportedRequest(f'Unsupported extensions: {", ".join(extensions.keys())}')

    @wrap_request_errors
    def validate(self, request: Request):
        if not isinstance(request, Request):
            raise TypeError('Expected an instance of Request')
        self._validate(request)

    @wrap_request_errors
    def send(self, request: Request) -> Response:
        if not isinstance(request, Request):
            raise TypeError('Expected an instance of Request')
        return self._send(request)

    @abc.abstractmethod
    def _send(self, request: Request):
        """Handle a request from start to finish. Redefine in subclasses."""

    def close(self):
        pass

    @classproperty