|
24 | 24 | Tuple,
|
25 | 25 | Type,
|
26 | 26 | Union,
|
27 |
| - cast, |
28 | 27 | )
|
29 | 28 |
|
30 | 29 | import attr
|
@@ -291,19 +290,20 @@ def __init__(
|
291 | 290 | ):
|
292 | 291 | if loop is None:
|
293 | 292 | 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): |
297 | 294 | raise ValueError(
|
298 | 295 | f"Method cannot contain non-token characters {method!r} "
|
299 |
| - "(found at least {match.group()!r})" |
| 296 | + f"(found at least {match.group()!r})" |
300 | 297 | )
|
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 |
304 | 302 | # FIXME: session is None in tests only, need to fix tests
|
305 | 303 | # 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 |
307 | 307 | if params:
|
308 | 308 | url = url.extend_query(params)
|
309 | 309 | self.original_url = url
|
@@ -338,9 +338,7 @@ def __init__(
|
338 | 338 | if data is not None or self.method not in self.GET_METHODS:
|
339 | 339 | self.update_transfer_encoding()
|
340 | 340 | 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 |
344 | 342 |
|
345 | 343 | def __reset_writer(self, _: object = None) -> None:
|
346 | 344 | self.__writer = None
|
|
0 commit comments