From: Tom Christie Date: Thu, 11 Jan 2024 15:30:16 +0000 (+0000) Subject: Error if missing version arguments X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=060e50b479255a630615f76cb86d82beda0e1816;p=thirdparty%2Fhttpx.git Error if missing version arguments --- diff --git a/httpx/_config.py b/httpx/_config.py index 7b786a91..00da0319 100644 --- a/httpx/_config.py +++ b/httpx/_config.py @@ -366,10 +366,12 @@ class Proxy: class Version: def __init__(self, *versions: str) -> None: self._versions = sorted(set(versions)) + if not versions: + raise ValueError("Missing HTTP version.") if any([version not in ["HTTP/1.1", "HTTP/2"] for version in versions]): raise ValueError("Supported versions are 'HTTP/1.1' and 'HTTP/2'") - def __contains__(self, version: str) -> bool: + def __contains__(self, version: str, /) -> bool: return version in self._versions def __repr__(self) -> str: diff --git a/tests/test_config.py b/tests/test_config.py index d24c54bb..9f32134a 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -231,5 +231,7 @@ def test_version(): def test_invalid_version(): + with pytest.raises(ValueError): + httpx.Version() with pytest.raises(ValueError): httpx.Version("HTTP/3")