From: Can Sarıgöl Date: Sun, 28 Jul 2019 16:40:05 +0000 (+0300) Subject: Add additional flake8 plugins (#157) X-Git-Tag: 0.7.0~38 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7e9110b9784a085899ad7f6516c8666561007b1f;p=thirdparty%2Fhttpx.git Add additional flake8 plugins (#157) --- diff --git a/httpx/client.py b/httpx/client.py index 8e20cf2b..7bf759aa 100644 --- a/httpx/client.py +++ b/httpx/client.py @@ -623,14 +623,14 @@ class Client(BaseClient): coroutine = self.send args = [request] - kwargs = dict( - stream=True, - auth=auth, - allow_redirects=allow_redirects, - verify=verify, - cert=cert, - timeout=timeout, - ) + kwargs = { + "stream": True, + "auth": auth, + "allow_redirects": allow_redirects, + "verify": verify, + "cert": cert, + "timeout": timeout, + } async_response = concurrency_backend.run(coroutine, *args, **kwargs) content = getattr( diff --git a/httpx/models.py b/httpx/models.py index 04754af4..d227948e 100644 --- a/httpx/models.py +++ b/httpx/models.py @@ -434,7 +434,7 @@ class Headers(typing.MutableMapping[str, str]): set_value = value.encode(self.encoding) found_indexes = [] - for idx, (item_key, item_value) in enumerate(self._list): + for idx, (item_key, _) in enumerate(self._list): if item_key == set_key: found_indexes.append(idx) @@ -454,7 +454,7 @@ class Headers(typing.MutableMapping[str, str]): del_key = key.lower().encode(self.encoding) pop_indexes = [] - for idx, (item_key, item_value) in enumerate(self._list): + for idx, (item_key, _) in enumerate(self._list): if item_key == del_key: pop_indexes.append(idx) @@ -463,7 +463,7 @@ class Headers(typing.MutableMapping[str, str]): def __contains__(self, key: typing.Any) -> bool: get_header_key = key.lower().encode(self.encoding) - for header_key, header_value in self._list: + for header_key, _ in self._list: if header_key == get_header_key: return True return False @@ -705,7 +705,7 @@ class BaseResponse: def content(self) -> bytes: if not hasattr(self, "_content"): if hasattr(self, "_raw_content"): - raw_content = getattr(self, "_raw_content") # type: bytes + raw_content = self._raw_content # type: ignore content = self.decoder.decode(raw_content) content += self.decoder.flush() self._content = content @@ -1033,25 +1033,25 @@ class Cookies(MutableMapping): """ Set a cookie value by name. May optionally include domain and path. """ - kwargs = dict( - version=0, - name=name, - value=value, - port=None, - port_specified=False, - domain=domain, - domain_specified=bool(domain), - domain_initial_dot=domain.startswith("."), - path=path, - path_specified=bool(path), - secure=False, - expires=None, - discard=True, - comment=None, - comment_url=None, - rest={"HttpOnly": None}, - rfc2109=False, - ) + kwargs = { + "version": 0, + "name": name, + "value": value, + "port": None, + "port_specified": False, + "domain": domain, + "domain_specified": bool(domain), + "domain_initial_dot": domain.startswith("."), + "path": path, + "path_specified": bool(path), + "secure": False, + "expires": None, + "discard": True, + "comment": None, + "comment_url": None, + "rest": {"HttpOnly": None}, + "rfc2109": False, + } cookie = Cookie(**kwargs) # type: ignore self.jar.set_cookie(cookie) @@ -1131,7 +1131,7 @@ class Cookies(MutableMapping): return (cookie.name for cookie in self.jar) def __bool__(self) -> bool: - for cookie in self.jar: + for _ in self.jar: return True return False diff --git a/requirements.txt b/requirements.txt index 13f45745..98e2d237 100644 --- a/requirements.txt +++ b/requirements.txt @@ -17,6 +17,8 @@ autoflake black cryptography flake8 +flake8-bugbear +flake8-comprehensions isort mypy pytest diff --git a/scripts/lint b/scripts/lint index fb2e81ab..a1b85cce 100755 --- a/scripts/lint +++ b/scripts/lint @@ -10,7 +10,7 @@ set -x ${PREFIX}autoflake --in-place --recursive httpx tests setup.py ${PREFIX}isort --multi-line=3 --trailing-comma --force-grid-wrap=0 --combine-as --line-width 88 --recursive --apply httpx tests setup.py ${PREFIX}black httpx tests setup.py -${PREFIX}flake8 --max-line-length=88 --ignore=W503,E203 httpx tests setup.py +${PREFIX}flake8 --max-line-length=88 --ignore=W503,E203,B305 httpx tests setup.py ${PREFIX}mypy httpx --ignore-missing-imports --disallow-untyped-defs scripts/clean diff --git a/tests/dispatch/test_connection_pools.py b/tests/dispatch/test_connection_pools.py index 14fd40c6..21ed5f6e 100644 --- a/tests/dispatch/test_connection_pools.py +++ b/tests/dispatch/test_connection_pools.py @@ -136,13 +136,15 @@ async def test_premature_response_close(server): @pytest.mark.asyncio async def test_keepalive_connection_closed_by_server_is_reestablished(server): """ - Upon keep-alive connection closed by remote a new connection should be reestablished. + Upon keep-alive connection closed by remote a new connection + should be reestablished. """ async with httpx.ConnectionPool() as http: response = await http.request("GET", "http://127.0.0.1:8000/") await response.read() - await server.shutdown() # shutdown the server to close the keep-alive connection + # shutdown the server to close the keep-alive connection + await server.shutdown() await server.startup() response = await http.request("GET", "http://127.0.0.1:8000/") @@ -154,13 +156,15 @@ async def test_keepalive_connection_closed_by_server_is_reestablished(server): @pytest.mark.asyncio async def test_keepalive_http2_connection_closed_by_server_is_reestablished(server): """ - Upon keep-alive connection closed by remote a new connection should be reestablished. + Upon keep-alive connection closed by remote a new connection + should be reestablished. """ async with httpx.ConnectionPool() as http: response = await http.request("GET", "http://127.0.0.1:8000/") await response.read() - await server.shutdown() # shutdown the server to close the keep-alive connection + # shutdown the server to close the keep-alive connection + await server.shutdown() await server.startup() response = await http.request("GET", "http://127.0.0.1:8000/") diff --git a/tests/models/test_responses.py b/tests/models/test_responses.py index dddfb4fb..ddec72e6 100644 --- a/tests/models/test_responses.py +++ b/tests/models/test_responses.py @@ -256,7 +256,7 @@ def test_unknown_status_code(): def test_json_with_specified_encoding(): - data = dict(greeting="hello", recipient="world") + data = {"greeting": "hello", "recipient": "world"} content = json.dumps(data).encode("utf-16") headers = {"Content-Type": "application/json, charset=utf-16"} response = httpx.Response(200, content=content, headers=headers) @@ -264,7 +264,7 @@ def test_json_with_specified_encoding(): def test_json_with_options(): - data = dict(greeting="hello", recipient="world", amount=1) + data = {"greeting": "hello", "recipient": "world", "amount": 1} content = json.dumps(data).encode("utf-16") headers = {"Content-Type": "application/json, charset=utf-16"} response = httpx.Response(200, content=content, headers=headers) @@ -272,7 +272,7 @@ def test_json_with_options(): def test_json_without_specified_encoding(): - data = dict(greeting="hello", recipient="world") + data = {"greeting": "hello", "recipient": "world"} content = json.dumps(data).encode("utf-32-be") headers = {"Content-Type": "application/json"} response = httpx.Response(200, content=content, headers=headers) @@ -280,7 +280,7 @@ def test_json_without_specified_encoding(): def test_json_without_specified_encoding_decode_error(): - data = dict(greeting="hello", recipient="world") + data = {"greeting": "hello", "recipient": "world"} content = json.dumps(data).encode("utf-32-be") headers = {"Content-Type": "application/json"} # force incorrect guess from `guess_json_utf` to trigger error diff --git a/tests/models/test_url.py b/tests/models/test_url.py index 01489acd..34e2e1a5 100644 --- a/tests/models/test_url.py +++ b/tests/models/test_url.py @@ -1,6 +1,7 @@ +import pytest + from httpx import URL from httpx.exceptions import InvalidURL -import pytest def test_idna_url(): @@ -46,10 +47,14 @@ def test_url_join(): Some basic URL joining tests. """ url = URL("https://example.org:123/path/to/somewhere") - assert url.join('/somewhere-else') == "https://example.org:123/somewhere-else" - assert url.join('somewhere-else') == "https://example.org:123/path/to/somewhere-else" - assert url.join('../somewhere-else') == "https://example.org:123/path/somewhere-else" - assert url.join('../../somewhere-else') == "https://example.org:123/somewhere-else" + assert url.join("/somewhere-else") == "https://example.org:123/somewhere-else" + assert ( + url.join("somewhere-else") == "https://example.org:123/path/to/somewhere-else" + ) + assert ( + url.join("../somewhere-else") == "https://example.org:123/path/somewhere-else" + ) + assert url.join("../../somewhere-else") == "https://example.org:123/somewhere-else" def test_url_join_rfc3986(): diff --git a/tests/test_multipart.py b/tests/test_multipart.py index 354bccee..a3e6eb59 100644 --- a/tests/test_multipart.py +++ b/tests/test_multipart.py @@ -117,7 +117,8 @@ def test_multipart_encode(): '--{0}\r\nContent-Disposition: form-data; name="d"\r\n\r\nff\r\n' '--{0}\r\nContent-Disposition: form-data; name="d"\r\n\r\nfff\r\n' '--{0}\r\nContent-Disposition: form-data; name="f"\r\n\r\n\r\n' - '--{0}\r\nContent-Disposition: form-data; name="file"; filename="name.txt"\r\n' + '--{0}\r\nContent-Disposition: form-data; name="file";' + ' filename="name.txt"\r\n' "Content-Type: text/plain\r\n\r\n\r\n" "--{0}--\r\n" "".format(boundary).encode("ascii")