]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Error if missing version arguments
authorTom Christie <tom.christie@krakentechnologies.ltd>
Thu, 11 Jan 2024 15:30:16 +0000 (15:30 +0000)
committerTom Christie <tom.christie@krakentechnologies.ltd>
Thu, 11 Jan 2024 15:30:16 +0000 (15:30 +0000)
httpx/_config.py
tests/test_config.py

index 7b786a91ee51a6c2ba9a046a70c913cd76b69bac..00da0319d7d19d2571c89850d03e9071955ae410 100644 (file)
@@ -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:
index d24c54bb3ec05c338f2b1c6ad423e45a75f0e546..9f32134af047f30b5ca799e493450f4e3bc23e1f 100644 (file)
@@ -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")