]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Use ruff instead of flake8, autoflake and isort (#2648)
authorMarcelo Trylesinski <marcelotryle@gmail.com>
Wed, 5 Apr 2023 10:37:10 +0000 (12:37 +0200)
committerGitHub <noreply@github.com>
Wed, 5 Apr 2023 10:37:10 +0000 (12:37 +0200)
* Use ruff instead of flake8, autoflake and isort

* Update pyproject.toml

httpx/_urls.py
pyproject.toml
requirements.txt
scripts/check
scripts/lint
setup.cfg
tests/client/test_async_client.py
tests/models/test_requests.py
tests/models/test_responses.py
tests/test_exceptions.py
tests/test_wsgi.py

index 6f5dc6a5435874b3b65f77962624d3be3a97f090..b023941b623fcde813f18f474c6861b4d1ce5688 100644 (file)
@@ -3,7 +3,7 @@ from urllib.parse import parse_qs, unquote
 
 import idna
 
-from ._types import PrimitiveData, QueryParamTypes, RawURL, URLTypes
+from ._types import QueryParamTypes, RawURL, URLTypes
 from ._urlparse import urlencode, urlparse
 from ._utils import primitive_value_to_str
 
@@ -422,7 +422,6 @@ class QueryParams(typing.Mapping[str, str]):
 
         value = args[0] if args else kwargs
 
-        items: typing.Sequence[typing.Tuple[str, PrimitiveData]]
         if value is None or isinstance(value, (str, bytes)):
             value = value.decode("ascii") if isinstance(value, bytes) else value
             self._dict = parse_qs(value, keep_blank_values=True)
index e5bd0d993b570ce0cb86e7adca290106bc08bbb9..d74fe7bf96f5463acc3789ea5f3963ab61f9b96b 100644 (file)
@@ -90,3 +90,12 @@ text = "\n---\n\n[Full changelog](https://github.com/encode/httpx/blob/master/CH
 [[tool.hatch.metadata.hooks.fancy-pypi-readme.substitutions]]
 pattern = 'src="(docs/img/.*?)"'
 replacement = 'src="https://raw.githubusercontent.com/encode/httpx/master/\1"'
+
+# https://beta.ruff.rs/docs/configuration/#using-rufftoml
+[tool.ruff]
+select = ["E", "F", "I", "B", "PIE"]
+ignore = ["B904", "B028"]
+line-length = 120
+
+[tool.ruff.isort]
+combine-as-imports = true
index 938e0a67c4ea098012fcd0b28d36d26d6b13e8ca..604af0c24ce4354cf2be5297d0f727103ba625f5 100644 (file)
@@ -19,19 +19,13 @@ build==0.10.0
 twine==4.0.2
 
 # Tests & Linting
-autoflake==1.7.7
 black==23.3.0
 coverage==7.2.2
 cryptography==39.0.1
-flake8==3.9.2
-flake8-bugbear==23.1.20
-flake8-pie==0.16.0; python_version>='3.7'
-importlib-metadata==4.13.0; python_version>='3.7'
-isort==5.11.4; python_version<'3.8'
-isort==5.12.0; python_version>='3.8'
 mypy==1.0.1
 types-certifi==2021.10.8.2
 pytest==7.2.2
+ruff==0.0.260
 trio==0.22.0
 trio-typing==0.7.0
 trustme==0.9.0
index dcde8cd1f2c139f4750324c6f00a6f8043af3e06..1ac6b99072c64110a603cf8d2947bc4967208ddb 100755 (executable)
@@ -10,6 +10,5 @@ set -x
 
 ./scripts/sync-version
 ${PREFIX}black --check --diff --target-version=py37 $SOURCE_FILES
-${PREFIX}flake8 $SOURCE_FILES
 ${PREFIX}mypy $SOURCE_FILES
-${PREFIX}isort --check --diff --project=httpx $SOURCE_FILES
+${PREFIX}ruff check --diff $SOURCE_FILES
index 81851c6405e55611196a35bb47d35e3721be189d..7a9e89d98bf3e565a361450aadea7d2c2a8845c0 100755 (executable)
@@ -8,6 +8,5 @@ export SOURCE_FILES="httpx tests"
 
 set -x
 
-${PREFIX}autoflake --in-place --recursive $SOURCE_FILES
-${PREFIX}isort --project=httpx $SOURCE_FILES
+${PREFIX}ruff --fix $SOURCE_FILES
 ${PREFIX}black --target-version=py37 $SOURCE_FILES
index c0bb07dd9b2f9fdf1664d716e8181de3f4431ef3..728160bf8656ed318fc96ef04a2c9877c0c2d9fb 100644 (file)
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,7 +1,3 @@
-[flake8]
-ignore = W503, E203, B305, PIE801
-max-line-length = 120
-
 [mypy]
 ignore_missing_imports = True
 strict = True
@@ -10,10 +6,6 @@ strict = True
 disallow_untyped_defs = False
 check_untyped_defs = True
 
-[tool:isort]
-profile = black
-combine_as_imports = True
-
 [tool:pytest]
 addopts = -rxXs
 filterwarnings =
index 5be0de3b12d83ffdf3515165fa789d57134d8565..7fa9a77948377a35ad316d634457c6a2d8e54bd1 100644 (file)
@@ -84,7 +84,7 @@ async def test_access_content_stream_response(server):
 
     assert response.status_code == 200
     with pytest.raises(httpx.ResponseNotRead):
-        response.content
+        response.content  # noqa: B018
 
 
 @pytest.mark.anyio
index 690b0e17df4e1638295523edd75c82084ad796a0..d0d4f11d3284dd2c57a7f4e5941d4bbb2b8d9763 100644 (file)
@@ -105,7 +105,7 @@ def test_cannot_access_streaming_content_without_read():
 
     request = httpx.Request("POST", "http://example.org", content=streaming_body())
     with pytest.raises(httpx.RequestNotRead):
-        request.content
+        request.content  # noqa: B018
 
 
 def test_transfer_encoding_header():
@@ -201,7 +201,7 @@ async def test_request_async_streaming_content_picklable():
     request = httpx.Request("POST", "http://example.org", content=data)
     pickle_request = pickle.loads(pickle.dumps(request))
     with pytest.raises(httpx.RequestNotRead):
-        pickle_request.content
+        pickle_request.content  # noqa: B018
     with pytest.raises(httpx.StreamClosed):
         await pickle_request.aread()
 
@@ -218,7 +218,7 @@ def test_request_generator_content_picklable():
     request = httpx.Request("POST", "http://example.org", content=content())
     pickle_request = pickle.loads(pickle.dumps(request))
     with pytest.raises(httpx.RequestNotRead):
-        pickle_request.content
+        pickle_request.content  # noqa: B018
     with pytest.raises(httpx.StreamClosed):
         pickle_request.read()
 
index b0ac41889420fc74763a67eaf1ee3fdf459dd128..4ec7e4b0ba7e81979131d0cf915e393cb1f4b142 100644 (file)
@@ -748,7 +748,7 @@ async def test_elapsed_not_available_until_closed():
     )
 
     with pytest.raises(RuntimeError):
-        response.elapsed
+        response.elapsed  # noqa: B018
 
 
 def test_unknown_status_code():
@@ -909,7 +909,7 @@ def test_cannot_access_unset_request():
     response = httpx.Response(200, content=b"Hello, world!")
 
     with pytest.raises(RuntimeError):
-        response.request
+        response.request  # noqa: B018
 
 
 def test_generator_with_transfer_encoding_header():
@@ -952,7 +952,7 @@ async def test_response_async_streaming_picklable():
     response = httpx.Response(200, content=async_streaming_body())
     pickle_response = pickle.loads(pickle.dumps(response))
     with pytest.raises(httpx.ResponseNotRead):
-        pickle_response.content
+        pickle_response.content  # noqa: B018
     with pytest.raises(httpx.StreamClosed):
         await pickle_response.aread()
     assert pickle_response.is_stream_consumed is False
index e17bc1ae95c706a523ee4a4d8aedf7c3d9464594..6547ab37a52e9aeb2d3123da0b372d92982c5334 100644 (file)
@@ -53,7 +53,7 @@ def test_request_attribute() -> None:
     # Exception without request attribute
     exc = httpx.ReadTimeout("Read operation timed out")
     with pytest.raises(RuntimeError):
-        exc.request
+        exc.request  # noqa: B018
 
     # Exception with request attribute
     request = httpx.Request("GET", "https://www.example.com")
index 4d66c2c3650b8e90197443628a4c09178573869d..ff3f24ed02c52ca2499d2e6cb75cea63b4d21769 100644 (file)
@@ -161,7 +161,7 @@ def test_wsgi_server_port(url: str, expected_server_port: str) -> None:
     SERVER_PORT is populated correctly from the requested URL.
     """
     hello_world_app = application_factory([b"Hello, World!"])
-    server_port: str
+    server_port: typing.Optional[str] = None
 
     def app(environ, start_response):
         nonlocal server_port