From: plotski <49732644+plotski@users.noreply.github.com> Date: Thu, 5 Nov 2020 10:46:22 +0000 (+0000) Subject: Include invalid name/value when raising TypeError in DataField (#1368) X-Git-Tag: 0.17.0~34 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=589c6e0f2f4f3821095bfc247417aa98a5dad838;p=thirdparty%2Fhttpx.git Include invalid name/value when raising TypeError in DataField (#1368) --- diff --git a/httpx/_client.py b/httpx/_client.py index d15c0045..2e9bd48d 100644 --- a/httpx/_client.py +++ b/httpx/_client.py @@ -379,7 +379,7 @@ class BaseClient: elif callable(auth): return FunctionAuth(func=auth) else: - raise TypeError('Invalid "auth" argument.') + raise TypeError(f'Invalid "auth" argument: {auth!r}') def _build_request_auth( self, request: Request, auth: typing.Union[AuthTypes, UnsetType] = UNSET diff --git a/httpx/_models.py b/httpx/_models.py index c981c740..8450690a 100644 --- a/httpx/_models.py +++ b/httpx/_models.py @@ -130,7 +130,7 @@ class URL: self._uri_reference = url._uri_reference else: raise TypeError( - f"Invalid type for url. Expected str or httpx.URL, got {type(url)}" + f"Invalid type for url. Expected str or httpx.URL, got {type(url)}: {url!r}" ) # Add any query parameters, merging with any in the URL if needed. diff --git a/httpx/_multipart.py b/httpx/_multipart.py index fc81e6fa..f690afc9 100644 --- a/httpx/_multipart.py +++ b/httpx/_multipart.py @@ -19,9 +19,13 @@ class DataField: def __init__(self, name: str, value: typing.Union[str, bytes]) -> None: if not isinstance(name, str): - raise TypeError("Invalid type for name. Expected str.") + raise TypeError( + f"Invalid type for name. Expected str, got {type(name)}: {name!r}" + ) if not isinstance(value, (str, bytes)): - raise TypeError("Invalid type for value. Expected str or bytes.") + raise TypeError( + f"Invalid type for value. Expected str or bytes, got {type(value)}: {value!r}" + ) self.name = name self.value = value diff --git a/tests/test_multipart.py b/tests/test_multipart.py index d2932ee0..8852c9f9 100644 --- a/tests/test_multipart.py +++ b/tests/test_multipart.py @@ -55,6 +55,7 @@ def test_multipart_invalid_key(key): files=files, ) assert "Invalid type for name" in str(e.value) + assert repr(key) in str(e.value) @pytest.mark.parametrize(("value"), (1, 2.3, None, [None, "abc"], {None: "abc"}))