]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Add additional flake8 plugins (#157)
authorCan Sarıgöl <ertugrulsarigol@gmail.com>
Sun, 28 Jul 2019 16:40:05 +0000 (19:40 +0300)
committerSeth Michael Larson <sethmichaellarson@gmail.com>
Sun, 28 Jul 2019 16:40:05 +0000 (11:40 -0500)
httpx/client.py
httpx/models.py
requirements.txt
scripts/lint
tests/dispatch/test_connection_pools.py
tests/models/test_responses.py
tests/models/test_url.py
tests/test_multipart.py

index 8e20cf2b97f617954154fd3d5ff032464cfdfeb1..7bf759aa4bdd917d056dc3eecd615ac0f6a5c2ae 100644 (file)
@@ -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(
index 04754af4553a8409fff546575e7435293370b645..d227948e3f526dfdd0dd85fcaf84f7bf39bd1539 100644 (file)
@@ -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
 
index 13f45745f3bbd93e102dd1d947399c4c21d20da4..98e2d237286a1cf4f379bc56eded8da604196ecf 100644 (file)
@@ -17,6 +17,8 @@ autoflake
 black
 cryptography
 flake8
+flake8-bugbear
+flake8-comprehensions
 isort
 mypy
 pytest
index fb2e81ab57fb218c0fa0a5269dd44790c2ce13e4..a1b85ccea16267e413df1f0b1d86ae4607828bd3 100755 (executable)
@@ -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
index 14fd40c62e8fe57299a19421ebe69ef19446580e..21ed5f6ea189f125ea256707656f62bfe4e959a8 100644 (file)
@@ -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/")
index dddfb4fb5ffe3900e0c8406bc283daf069e8ab98..ddec72e6d133194c20d764aee10aec47c9902bff 100644 (file)
@@ -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
index 01489acd68a3fa845b4ae83282b3d6a78e440e08..34e2e1a57d901cffef97fede84dcf090dac179c6 100644 (file)
@@ -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():
index 354bccee7361f9b078c9b01d42730102610ea898..a3e6eb59eb75c56ea6892a2f163560121b1428c3 100644 (file)
@@ -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<file content>\r\n"
             "--{0}--\r\n"
             "".format(boundary).encode("ascii")