Skip to content
Myr

Include invalid name/value when raising TypeError in DataField (#1368)

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

authored by plotski · committed by GitHub · parent 1bc3b01 · Browse files · 4 files+9 added−4 removed
This commit

State

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

Diff stats

4 files+9 added−4 removed

  • tests:+1 added−0 removed
  • other:+8 added−4 removed

4 files+9 added−4 removed

modified:httpx/_client.py+1 added-1 removed
377 unmodified lines
378 return auth379 elif callable(auth):380 return FunctionAuth(func=auth)381 else:382 raise TypeError('Invalid "auth" argument.')382 raise TypeError(f'Invalid "auth" argument: {auth!r}')383384 def _build_request_auth(385 self, request: Request, auth: typing.Union[AuthTypes, UnsetType] = UNSET386 ) -> Auth:
1460 unmodified lines
modified:httpx/_models.py+1 added-1 removed
128 unmodified lines
129 elif isinstance(url, URL):130 self._uri_reference = url._uri_reference131 else:132 raise TypeError(133 f"Invalid type for url. Expected str or httpx.URL, got {type(url)}"133 f"Invalid type for url. Expected str or httpx.URL, got {type(url)}: {url!r}"134 )135136 # Add any query parameters, merging with any in the URL if needed.137 if params:
1343 unmodified lines
modified:httpx/_multipart.py+6 added-2 removed
17 unmodified lines
18 """1920 def __init__(self, name: str, value: typing.Union[str, bytes]) -> None:21 if not isinstance(name, str):22 raise TypeError("Invalid type for name. Expected str.")22 raise TypeError(23 f"Invalid type for name. Expected str, got {type(name)}: {name!r}"24 )25 if not isinstance(value, (str, bytes)):24 raise TypeError("Invalid type for value. Expected str or bytes.")26 raise TypeError(27 f"Invalid type for value. Expected str or bytes, got {type(value)}: {value!r}"28 )29 self.name = name30 self.value = value3132 def render_headers(self) -> bytes:
172 unmodified lines
modified:tests/test_multipart.py+1 added
53 unmodified lines
54 data=data,55 files=files,56 )57 assert "Invalid type for name" in str(e.value)58 assert repr(key) in str(e.value)596061@pytest.mark.parametrize(("value"), (1, 2.3, None, [None, "abc"], {None: "abc"}))62def test_multipart_invalid_value(value):
206 unmodified lines