Skip to content
Myr

Add additional flake8 plugins (#157)

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

authored by Can Sarıgöl · committed by Seth Michael Larson · parent 2cc8bea · Browse files · 8 files+59 added−47 removed
This commit

State

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

Diff stats

8 files+59 added−47 removed

  • tests:+24 added−14 removed
  • other:+35 added−33 removed

8 files+59 added−47 removed

modified:httpx/client.py+8 added-8 removed
621 unmodified lines
622 concurrency_backend = self.concurrency_backend623624 coroutine = self.send625 args = [request]626 kwargs = dict(627 stream=True,628 auth=auth,629 allow_redirects=allow_redirects,630 verify=verify,631 cert=cert,632 timeout=timeout,633 )626 kwargs = {627 "stream": True,628 "auth": auth,629 "allow_redirects": allow_redirects,630 "verify": verify,631 "cert": cert,632 "timeout": timeout,633 }634 async_response = concurrency_backend.run(coroutine, *args, **kwargs)635636 content = getattr(637 async_response, "_raw_content", getattr(async_response, "_raw_stream", None)
258 unmodified lines
modified:httpx/models.py+24 added-24 removed
432 unmodified lines
433 set_key = key.lower().encode(self.encoding)434 set_value = value.encode(self.encoding)435436 found_indexes = []437 for idx, (item_key, item_value) in enumerate(self._list):437 for idx, (item_key, _) in enumerate(self._list):438 if item_key == set_key:439 found_indexes.append(idx)440441 for idx in reversed(found_indexes[1:]):
11 unmodified lines
453 """454 del_key = key.lower().encode(self.encoding)455456 pop_indexes = []457 for idx, (item_key, item_value) in enumerate(self._list):457 for idx, (item_key, _) in enumerate(self._list):458 if item_key == del_key:459 pop_indexes.append(idx)460461 for idx in reversed(pop_indexes):462 del self._list[idx]463464 def __contains__(self, key: typing.Any) -> bool:465 get_header_key = key.lower().encode(self.encoding)466 for header_key, header_value in self._list:466 for header_key, _ in self._list:467 if header_key == get_header_key:468 return True469 return False470
233 unmodified lines
704 @property705 def content(self) -> bytes:706 if not hasattr(self, "_content"):707 if hasattr(self, "_raw_content"):708 raw_content = getattr(self, "_raw_content") # type: bytes708 raw_content = self._raw_content # type: ignore709 content = self.decoder.decode(raw_content)710 content += self.decoder.flush()711 self._content = content712 else:
319 unmodified lines
1032 def set(self, name: str, value: str, domain: str = "", path: str = "/") -> None:1033 """1034 Set a cookie value by name. May optionally include domain and path.1035 """1036 kwargs = dict(1037 version=0,1038 name=name,1039 value=value,1040 port=None,1041 port_specified=False,1042 domain=domain,1043 domain_specified=bool(domain),1044 domain_initial_dot=domain.startswith("."),1045 path=path,1046 path_specified=bool(path),1047 secure=False,1048 expires=None,1049 discard=True,1050 comment=None,1051 comment_url=None,1052 rest={"HttpOnly": None},1053 rfc2109=False,1054 )1036 kwargs = {1037 "version": 0,1038 "name": name,1039 "value": value,1040 "port": None,1041 "port_specified": False,1042 "domain": domain,1043 "domain_specified": bool(domain),1044 "domain_initial_dot": domain.startswith("."),1045 "path": path,1046 "path_specified": bool(path),1047 "secure": False,1048 "expires": None,1049 "discard": True,1050 "comment": None,1051 "comment_url": None,1052 "rest": {"HttpOnly": None},1053 "rfc2109": False,1054 }1055 cookie = Cookie(**kwargs) # type: ignore1056 self.jar.set_cookie(cookie)10571058 def get( # type: ignore
71 unmodified lines
1130 def __iter__(self) -> typing.Iterator[str]:1131 return (cookie.name for cookie in self.jar)11321133 def __bool__(self) -> bool:1134 for cookie in self.jar:1134 for _ in self.jar:1135 return True1136 return False11371138 class _CookieCompatRequest(urllib.request.Request):
31 unmodified lines
modified:scripts/lint+1 added-1 removed
8 unmodified lines
910${PREFIX}autoflake --in-place --recursive httpx tests setup.py11${PREFIX}isort --multi-line=3 --trailing-comma --force-grid-wrap=0 --combine-as --line-width 88 --recursive --apply httpx tests setup.py12${PREFIX}black httpx tests setup.py13${PREFIX}flake8 --max-line-length=88 --ignore=W503,E203 httpx tests setup.py13${PREFIX}flake8 --max-line-length=88 --ignore=W503,E203,B305 httpx tests setup.py14${PREFIX}mypy httpx --ignore-missing-imports --disallow-untyped-defs1516scripts/clean
modified:tests/dispatch/test_connection_pools.py+8 added-4 removed
134 unmodified lines
135136@pytest.mark.asyncio137async def test_keepalive_connection_closed_by_server_is_reestablished(server):138 """139 Upon keep-alive connection closed by remote a new connection should be reestablished.139 Upon keep-alive connection closed by remote a new connection140 should be reestablished.141 """142 async with httpx.ConnectionPool() as http:143 response = await http.request("GET", "http://127.0.0.1:8000/")144 await response.read()145145 await server.shutdown() # shutdown the server to close the keep-alive connection146 # shutdown the server to close the keep-alive connection147 await server.shutdown()148 await server.startup()149150 response = await http.request("GET", "http://127.0.0.1:8000/")151 await response.read()
3 unmodified lines
155156@pytest.mark.asyncio157async def test_keepalive_http2_connection_closed_by_server_is_reestablished(server):158 """157 Upon keep-alive connection closed by remote a new connection should be reestablished.159 Upon keep-alive connection closed by remote a new connection160 should be reestablished.161 """162 async with httpx.ConnectionPool() as http:163 response = await http.request("GET", "http://127.0.0.1:8000/")164 await response.read()165163 await server.shutdown() # shutdown the server to close the keep-alive connection166 # shutdown the server to close the keep-alive connection167 await server.shutdown()168 await server.startup()169170 response = await http.request("GET", "http://127.0.0.1:8000/")171 await response.read()
2 unmodified lines
modified:tests/models/test_responses.py+4 added-4 removed
254 unmodified lines
255 assert response.text == ""256257258def test_json_with_specified_encoding():259 data = dict(greeting="hello", recipient="world")259 data = {"greeting": "hello", "recipient": "world"}260 content = json.dumps(data).encode("utf-16")261 headers = {"Content-Type": "application/json, charset=utf-16"}262 response = httpx.Response(200, content=content, headers=headers)263 assert response.json() == data264265266def test_json_with_options():267 data = dict(greeting="hello", recipient="world", amount=1)267 data = {"greeting": "hello", "recipient": "world", "amount": 1}268 content = json.dumps(data).encode("utf-16")269 headers = {"Content-Type": "application/json, charset=utf-16"}270 response = httpx.Response(200, content=content, headers=headers)271 assert response.json(parse_int=str)["amount"] == "1"272273274def test_json_without_specified_encoding():275 data = dict(greeting="hello", recipient="world")275 data = {"greeting": "hello", "recipient": "world"}276 content = json.dumps(data).encode("utf-32-be")277 headers = {"Content-Type": "application/json"}278 response = httpx.Response(200, content=content, headers=headers)279 assert response.json() == data280281282def test_json_without_specified_encoding_decode_error():283 data = dict(greeting="hello", recipient="world")283 data = {"greeting": "hello", "recipient": "world"}284 content = json.dumps(data).encode("utf-32-be")285 headers = {"Content-Type": "application/json"}286 # force incorrect guess from `guess_json_utf` to trigger error287 with mock.patch("httpx.models.guess_json_utf", return_value="utf-32"):
3 unmodified lines
modified:tests/models/test_url.py+10 added-5 removed
1import pytest23from httpx import URL4from httpx.exceptions import InvalidURL3import pytest567def test_idna_url():8 url = URL("http://中国.icom.museum:80/")
37 unmodified lines
46 """47 Some basic URL joining tests.48 """49 url = URL("https://example.org:123/path/to/somewhere")49 assert url.join('/somewhere-else') == "https://example.org:123/somewhere-else"50 assert url.join('somewhere-else') == "https://example.org:123/path/to/somewhere-else"51 assert url.join('../somewhere-else') == "https://example.org:123/path/somewhere-else"52 assert url.join('../../somewhere-else') == "https://example.org:123/somewhere-else"50 assert url.join("/somewhere-else") == "https://example.org:123/somewhere-else"51 assert (52 url.join("somewhere-else") == "https://example.org:123/path/to/somewhere-else"53 )54 assert (55 url.join("../somewhere-else") == "https://example.org:123/path/somewhere-else"56 )57 assert url.join("../../somewhere-else") == "https://example.org:123/somewhere-else"585960def test_url_join_rfc3986():61 """
65 unmodified lines
modified:tests/test_multipart.py+2 added-1 removed
115 unmodified lines
116 '--{0}\r\nContent-Disposition: form-data; name="c"\r\n\r\n33\r\n'117 '--{0}\r\nContent-Disposition: form-data; name="d"\r\n\r\nff\r\n'118 '--{0}\r\nContent-Disposition: form-data; name="d"\r\n\r\nfff\r\n'119 '--{0}\r\nContent-Disposition: form-data; name="f"\r\n\r\n\r\n'120 '--{0}\r\nContent-Disposition: form-data; name="file"; filename="name.txt"\r\n'120 '--{0}\r\nContent-Disposition: form-data; name="file";'121 ' filename="name.txt"\r\n'122 "Content-Type: text/plain\r\n\r\n<file content>\r\n"123 "--{0}--\r\n"124 "".format(boundary).encode("ascii")125 )
modified:requirements.txt+2 added
15 unmodified lines
16autoflake17black18cryptography19flake820flake8-bugbear21flake8-comprehensions22isort23mypy24pytest25pytest-asyncio
3 unmodified lines