Skip to content
Myr

Raise TypeError if invalid parameter for HTTPVersionConfig (#253)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Can Sarıgöl · committed by Seth Michael Larson · parent fc261e8 · Browse files · 2 files+19 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+19 added−1 removed

  • tests:+10 added−0 removed
  • other:+9 added−1 removed

2 files+19 added−1 removed

modified:httpx/config.py+9 added-1 removed
249 unmodified lines
250 if isinstance(http_versions, str):251 self.http_versions = {http_versions.upper()}252 elif isinstance(http_versions, HTTPVersionConfig):253 self.http_versions = http_versions.http_versions254 elif isinstance(http_versions, typing.Iterable):255 self.http_versions = {256 version.upper() if isinstance(version, str) else version257 for version in http_versions258 }259 else:255 self.http_versions = {version.upper() for version in http_versions}260 raise TypeError(261 f"HTTP version should be a string or list of strings, "262 "but got {type(http_versions)}"263 )264265 for version in self.http_versions:266 if version not in ("HTTP/1.1", "HTTP/2"):267 raise ValueError(f"Unsupported HTTP version {version!r}.")
56 unmodified lines
modified:tests/test_config.py+10 added
113 unmodified lines
114 with pytest.raises(ValueError):115 httpx.HTTPVersionConfig("HTTP/9")116117118def test_invalid_http_version_type():119 with pytest.raises(TypeError):120 httpx.HTTPVersionConfig(123)121122123def test_invalid_http_version_list_type():124 with pytest.raises(ValueError):125 httpx.HTTPVersionConfig([123])126127128def test_empty_http_version():129 with pytest.raises(ValueError):130 httpx.HTTPVersionConfig([])131
42 unmodified lines