Skip to content
Myr

Improve list/dict comprehensions (#1036)

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

* Improve list/dict comprehensions * Dont make needless list() conversions before bytes.join()

authored by Taneli Hukkinen · committed by GitHub · parent c53172d · Browse files · 5 files+15 added−18 removed
This commit

State

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

Trailers

  • Co-authored-by: Florimond Manca <florimond.manca@gmail.com>

Diff stats

5 files+15 added−18 removed

  • tests:+9 added−9 removed
  • other:+6 added−9 removed

5 files+15 added−18 removed

modified:httpx/_transports/urllib3.py+3 added-6 removed
86 unmodified lines
87 with as_network_error(MaxRetryError, SSLError, socket.error):88 conn = self.pool.urlopen(89 method=method.decode(),90 url=url_str,91 headers=dict(92 [93 (key.decode("ascii"), value.decode("ascii"))94 for key, value in headers95 ]96 ),91 headers={92 key.decode("ascii"): value.decode("ascii") for key, value in headers93 },94 body=body,95 redirect=False,96 assert_same_host=False,97 retries=0,
51 unmodified lines
modified:httpx/_transports/wsgi.py+1 added-1 removed
81 unmodified lines
82 path, _, query = full_path.partition(b"?")83 environ = {84 "wsgi.version": (1, 0),85 "wsgi.url_scheme": scheme.decode("ascii"),86 "wsgi.input": io.BytesIO(b"".join([chunk for chunk in stream])),86 "wsgi.input": io.BytesIO(b"".join(stream)),87 "wsgi.errors": io.BytesIO(),88 "wsgi.multithread": True,89 "wsgi.multiprocess": False,90 "wsgi.run_once": False,
61 unmodified lines
modified:httpx/_models.py+2 added-2 removed
649 unmodified lines
650 """651 Read and return the request content.652 """653 if not hasattr(self, "_content"):654 self._content = b"".join([part for part in self.stream])654 self._content = b"".join(self.stream)655 # If a streaming request has been read entirely into memory, then656 # we can replace the stream with a raw bytes implementation,657 # to ensure that any non-replayable streams can still be used.658 self.stream = ByteStream(self._content)
235 unmodified lines
894 """895 Read and return the response content.896 """897 if not hasattr(self, "_content"):898 self._content = b"".join([part for part in self.iter_bytes()])898 self._content = b"".join(self.iter_bytes())899 return self._content900901 def iter_bytes(self) -> typing.Iterator[bytes]:902 """
300 unmodified lines
modified:tests/client/test_headers.py+3 added-3 removed
18 unmodified lines
19 timeout: typing.Dict[str, typing.Optional[float]] = None,20 ) -> typing.Tuple[21 bytes, int, bytes, typing.List[typing.Tuple[bytes, bytes]], ContentStream22 ]:23 headers_dict = dict(24 [(key.decode("ascii"), value.decode("ascii")) for key, value in headers]25 )23 headers_dict = {24 key.decode("ascii"): value.decode("ascii") for key, value in headers25 }26 body = JSONStream({"headers": headers_dict})27 return b"HTTP/1.1", 200, b"OK", [], body2829
153 unmodified lines
modified:tests/client/test_redirects.py+6 added-6 removed
98 unmodified lines
99 headers = [(b"location", b"https://example.org/cross_domain_target")]100 return b"HTTP/1.1", code, b"See Other", headers, ByteStream(b"")101102 elif path == b"/cross_domain_target":103 headers_dict = dict(104 [(key.decode("ascii"), value.decode("ascii")) for key, value in headers]105 )103 headers_dict = {104 key.decode("ascii"): value.decode("ascii") for key, value in headers105 }106 content = ByteStream(json.dumps({"headers": headers_dict}).encode())107 return b"HTTP/1.1", 200, b"OK", [], content108109 elif path == b"/redirect_body":
7 unmodified lines
117 return b"HTTP/1.1", code, b"See Other", headers, ByteStream(b"")118119 elif path == b"/redirect_body_target":120 content = b"".join(stream)121 headers_dict = dict(122 [(key.decode("ascii"), value.decode("ascii")) for key, value in headers]123 )121 headers_dict = {122 key.decode("ascii"): value.decode("ascii") for key, value in headers123 }124 body = ByteStream(125 json.dumps({"body": content.decode(), "headers": headers_dict}).encode()126 )127 return b"HTTP/1.1", 200, b"OK", [], body
358 unmodified lines