Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ruff instead of flake8, autoflake and isort #2648

Merged
merged 4 commits into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions httpx/_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

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

Expand Down Expand Up @@ -422,7 +422,6 @@ def __init__(

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)
Expand Down
9 changes: 9 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Kludex marked this conversation as resolved.
Show resolved Hide resolved
select = ["E", "F", "I", "B", "PIE"]
ignore = ["B904", "B028"]
line-length = 120
Kludex marked this conversation as resolved.
Show resolved Hide resolved

[tool.ruff.isort]
combine-as-imports = true
8 changes: 1 addition & 7 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions scripts/check
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 1 addition & 2 deletions scripts/lint
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 0 additions & 8 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
[flake8]
ignore = W503, E203, B305, PIE801
max-line-length = 120

[mypy]
ignore_missing_imports = True
strict = True
Expand All @@ -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 =
Expand Down
2 changes: 1 addition & 1 deletion tests/client/test_async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can I track down what a B018 is?

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's on the rules page: https://beta.ruff.rs/docs/rules/#flake8-bugbear-b

Should I add a comment here or ignore it globally?



@pytest.mark.anyio
Expand Down
6 changes: 3 additions & 3 deletions tests/models/test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def streaming_body() -> typing.Iterator[bytes]: # pragma: no cover

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():
Expand Down Expand Up @@ -201,7 +201,7 @@ async def streaming_body(data: bytes) -> typing.AsyncIterator[bytes]:
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()

Expand All @@ -218,7 +218,7 @@ def content() -> typing.Iterator[bytes]:
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()

Expand Down
6 changes: 3 additions & 3 deletions tests/models/test_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion tests/test_wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down