Skip to content

Commit daec2bd

Browse files
authored
Use ruff instead of flake8, autoflake and isort (#2648)
* Use ruff instead of flake8, autoflake and isort * Update pyproject.toml
1 parent ab8177c commit daec2bd

11 files changed

+22
-30
lines changed

httpx/_urls.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import idna
55

6-
from ._types import PrimitiveData, QueryParamTypes, RawURL, URLTypes
6+
from ._types import QueryParamTypes, RawURL, URLTypes
77
from ._urlparse import urlencode, urlparse
88
from ._utils import primitive_value_to_str
99

@@ -422,7 +422,6 @@ def __init__(
422422

423423
value = args[0] if args else kwargs
424424

425-
items: typing.Sequence[typing.Tuple[str, PrimitiveData]]
426425
if value is None or isinstance(value, (str, bytes)):
427426
value = value.decode("ascii") if isinstance(value, bytes) else value
428427
self._dict = parse_qs(value, keep_blank_values=True)

pyproject.toml

+9
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,12 @@ text = "\n---\n\n[Full changelog](https://github.com/encode/httpx/blob/master/CH
9090
[[tool.hatch.metadata.hooks.fancy-pypi-readme.substitutions]]
9191
pattern = 'src="(docs/img/.*?)"'
9292
replacement = 'src="https://raw.githubusercontent.com/encode/httpx/master/\1"'
93+
94+
# https://beta.ruff.rs/docs/configuration/#using-rufftoml
95+
[tool.ruff]
96+
select = ["E", "F", "I", "B", "PIE"]
97+
ignore = ["B904", "B028"]
98+
line-length = 120
99+
100+
[tool.ruff.isort]
101+
combine-as-imports = true

requirements.txt

+1-7
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,13 @@ build==0.10.0
1919
twine==4.0.2
2020

2121
# Tests & Linting
22-
autoflake==1.7.7
2322
black==23.3.0
2423
coverage==7.2.2
2524
cryptography==39.0.1
26-
flake8==3.9.2
27-
flake8-bugbear==23.1.20
28-
flake8-pie==0.16.0; python_version>='3.7'
29-
importlib-metadata==4.13.0; python_version>='3.7'
30-
isort==5.11.4; python_version<'3.8'
31-
isort==5.12.0; python_version>='3.8'
3225
mypy==1.0.1
3326
types-certifi==2021.10.8.2
3427
pytest==7.2.2
28+
ruff==0.0.260
3529
trio==0.22.0
3630
trio-typing==0.7.0
3731
trustme==0.9.0

scripts/check

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,5 @@ set -x
1010

1111
./scripts/sync-version
1212
${PREFIX}black --check --diff --target-version=py37 $SOURCE_FILES
13-
${PREFIX}flake8 $SOURCE_FILES
1413
${PREFIX}mypy $SOURCE_FILES
15-
${PREFIX}isort --check --diff --project=httpx $SOURCE_FILES
14+
${PREFIX}ruff check --diff $SOURCE_FILES

scripts/lint

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,5 @@ export SOURCE_FILES="httpx tests"
88

99
set -x
1010

11-
${PREFIX}autoflake --in-place --recursive $SOURCE_FILES
12-
${PREFIX}isort --project=httpx $SOURCE_FILES
11+
${PREFIX}ruff --fix $SOURCE_FILES
1312
${PREFIX}black --target-version=py37 $SOURCE_FILES

setup.cfg

-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
[flake8]
2-
ignore = W503, E203, B305, PIE801
3-
max-line-length = 120
4-
51
[mypy]
62
ignore_missing_imports = True
73
strict = True
@@ -10,10 +6,6 @@ strict = True
106
disallow_untyped_defs = False
117
check_untyped_defs = True
128

13-
[tool:isort]
14-
profile = black
15-
combine_as_imports = True
16-
179
[tool:pytest]
1810
addopts = -rxXs
1911
filterwarnings =

tests/client/test_async_client.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ async def test_access_content_stream_response(server):
8484

8585
assert response.status_code == 200
8686
with pytest.raises(httpx.ResponseNotRead):
87-
response.content
87+
response.content # noqa: B018
8888

8989

9090
@pytest.mark.anyio

tests/models/test_requests.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def streaming_body() -> typing.Iterator[bytes]: # pragma: no cover
105105

106106
request = httpx.Request("POST", "http://example.org", content=streaming_body())
107107
with pytest.raises(httpx.RequestNotRead):
108-
request.content
108+
request.content # noqa: B018
109109

110110

111111
def test_transfer_encoding_header():
@@ -201,7 +201,7 @@ async def streaming_body(data: bytes) -> typing.AsyncIterator[bytes]:
201201
request = httpx.Request("POST", "http://example.org", content=data)
202202
pickle_request = pickle.loads(pickle.dumps(request))
203203
with pytest.raises(httpx.RequestNotRead):
204-
pickle_request.content
204+
pickle_request.content # noqa: B018
205205
with pytest.raises(httpx.StreamClosed):
206206
await pickle_request.aread()
207207

@@ -218,7 +218,7 @@ def content() -> typing.Iterator[bytes]:
218218
request = httpx.Request("POST", "http://example.org", content=content())
219219
pickle_request = pickle.loads(pickle.dumps(request))
220220
with pytest.raises(httpx.RequestNotRead):
221-
pickle_request.content
221+
pickle_request.content # noqa: B018
222222
with pytest.raises(httpx.StreamClosed):
223223
pickle_request.read()
224224

tests/models/test_responses.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ async def test_elapsed_not_available_until_closed():
748748
)
749749

750750
with pytest.raises(RuntimeError):
751-
response.elapsed
751+
response.elapsed # noqa: B018
752752

753753

754754
def test_unknown_status_code():
@@ -909,7 +909,7 @@ def test_cannot_access_unset_request():
909909
response = httpx.Response(200, content=b"Hello, world!")
910910

911911
with pytest.raises(RuntimeError):
912-
response.request
912+
response.request # noqa: B018
913913

914914

915915
def test_generator_with_transfer_encoding_header():
@@ -952,7 +952,7 @@ async def test_response_async_streaming_picklable():
952952
response = httpx.Response(200, content=async_streaming_body())
953953
pickle_response = pickle.loads(pickle.dumps(response))
954954
with pytest.raises(httpx.ResponseNotRead):
955-
pickle_response.content
955+
pickle_response.content # noqa: B018
956956
with pytest.raises(httpx.StreamClosed):
957957
await pickle_response.aread()
958958
assert pickle_response.is_stream_consumed is False

tests/test_exceptions.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def test_request_attribute() -> None:
5353
# Exception without request attribute
5454
exc = httpx.ReadTimeout("Read operation timed out")
5555
with pytest.raises(RuntimeError):
56-
exc.request
56+
exc.request # noqa: B018
5757

5858
# Exception with request attribute
5959
request = httpx.Request("GET", "https://www.example.com")

tests/test_wsgi.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def test_wsgi_server_port(url: str, expected_server_port: str) -> None:
161161
SERVER_PORT is populated correctly from the requested URL.
162162
"""
163163
hello_world_app = application_factory([b"Hello, World!"])
164-
server_port: str
164+
server_port: typing.Optional[str] = None
165165

166166
def app(environ, start_response):
167167
nonlocal server_port

0 commit comments

Comments
 (0)