]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Include invalid name/value when raising TypeError in DataField (#1368)
authorplotski <49732644+plotski@users.noreply.github.com>
Thu, 5 Nov 2020 10:46:22 +0000 (10:46 +0000)
committerGitHub <noreply@github.com>
Thu, 5 Nov 2020 10:46:22 +0000 (10:46 +0000)
httpx/_client.py
httpx/_models.py
httpx/_multipart.py
tests/test_multipart.py

index d15c0045301e07c4739004f4edfe350e01fb38b3..2e9bd48dca6774a5906c64cb9f015d23fd7112fe 100644 (file)
@@ -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
index c981c740bf235d0a7c41dd5538f6c6155cd1190f..8450690a892a7c9083564bd6d434c12c2f7cb73c 100644 (file)
@@ -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.
index fc81e6fa186b9a4aecb9a324e738b65e226ead6b..f690afc9ae1c013cca6b71980d48114dfdb1344d 100644 (file)
@@ -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
 
index d2932ee0986220dc0d2c2ca6a3f3e6065ffe239d..8852c9f905269287612e791252c8a76ab1df5d81 100644 (file)
@@ -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"}))