Skip to content

Commit 5914dc5

Browse files
authored
[PR #9713/500a021 backport][3.11] Small cleanups to creating a ClientRequest (#9717)
1 parent d5bbb80 commit 5914dc5

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

aiohttp/client_reqrep.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
Tuple,
2525
Type,
2626
Union,
27-
cast,
2827
)
2928

3029
import attr
@@ -291,19 +290,20 @@ def __init__(
291290
):
292291
if loop is None:
293292
loop = asyncio.get_event_loop()
294-
295-
match = _CONTAINS_CONTROL_CHAR_RE.search(method)
296-
if match:
293+
if match := _CONTAINS_CONTROL_CHAR_RE.search(method):
297294
raise ValueError(
298295
f"Method cannot contain non-token characters {method!r} "
299-
"(found at least {match.group()!r})"
296+
f"(found at least {match.group()!r})"
300297
)
301-
302-
assert isinstance(url, URL), url
303-
assert isinstance(proxy, (URL, type(None))), proxy
298+
# URL forbids subclasses, so a simple type check is enough.
299+
assert type(url) is URL, url
300+
if proxy is not None:
301+
assert type(proxy) is URL, proxy
304302
# FIXME: session is None in tests only, need to fix tests
305303
# assert session is not None
306-
self._session = cast("ClientSession", session)
304+
if TYPE_CHECKING:
305+
assert session is not None
306+
self._session = session
307307
if params:
308308
url = url.extend_query(params)
309309
self.original_url = url
@@ -338,9 +338,7 @@ def __init__(
338338
if data is not None or self.method not in self.GET_METHODS:
339339
self.update_transfer_encoding()
340340
self.update_expect_continue(expect100)
341-
if traces is None:
342-
traces = []
343-
self._traces = traces
341+
self._traces = [] if traces is None else traces
344342

345343
def __reset_writer(self, _: object = None) -> None:
346344
self.__writer = None

0 commit comments

Comments
 (0)