Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small cleanups to creating a ClientRequest #9713

Merged
merged 3 commits into from
Nov 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions aiohttp/client_reqrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
Tuple,
Type,
Union,
cast,
)

from multidict import CIMultiDict, CIMultiDictProxy, MultiDict, MultiDictProxy
Expand Down Expand Up @@ -227,17 +226,20 @@ def __init__(
trust_env: bool = False,
server_hostname: Optional[str] = None,
):
match = _CONTAINS_CONTROL_CHAR_RE.search(method)
if match:
if match := _CONTAINS_CONTROL_CHAR_RE.search(method):
raise ValueError(
f"Method cannot contain non-token characters {method!r} "
f"(found at least {match.group()!r})"
)
assert isinstance(url, URL), url
assert isinstance(proxy, (URL, type(None))), proxy
# URL forbids subclasses, so a simple type check is enough.
assert type(url) is URL, url
if proxy is not None:
assert type(proxy) is URL, proxy
# FIXME: session is None in tests only, need to fix tests
# assert session is not None
self._session = cast("ClientSession", session)
if TYPE_CHECKING:
assert session is not None
self._session = session
if params:
url = url.extend_query(params)
self.original_url = url
Expand Down Expand Up @@ -271,9 +273,7 @@ def __init__(
if data is not None or self.method not in self.GET_METHODS:
self.update_transfer_encoding()
self.update_expect_continue(expect100)
if traces is None:
traces = []
self._traces = traces
self._traces = [] if traces is None else traces

def __reset_writer(self, _: object = None) -> None:
self.__writer = None
Expand Down
Loading