Skip to content

Commit

Permalink
Ruff linter: Use the default line-length
Browse files Browse the repository at this point in the history
  • Loading branch information
Tester authored and Tester committed Feb 13, 2024
1 parent 7b04cda commit 32620a0
Show file tree
Hide file tree
Showing 23 changed files with 335 additions and 230 deletions.
3 changes: 2 additions & 1 deletion httpcore/_async/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ def __init__(
async def handle_async_request(self, request: Request) -> Response:
if not self.can_handle_request(request.url.origin):
raise RuntimeError(
f"Attempted to send request to {request.url.origin} on connection to {self._origin}"
f"Attempted to send request to {request.url.origin}"
f" on connection to {self._origin}"
)

try:
Expand Down
18 changes: 11 additions & 7 deletions httpcore/_async/connection_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,10 @@ def __init__(
self._connections: List[AsyncConnectionInterface] = []
self._requests: List[AsyncPoolRequest] = []

# We only mutate the state of the connection pool within an 'optional_thread_lock'
# context. This holds a threading lock unless we're running in async mode,
# in which case it is a no-op.
# We only mutate the state of the connection pool
# within an 'optional_thread_lock' context.
# This holds a threading lock unless we're running in
# async mode, in which case it is a no-op.
self._optional_thread_lock = AsyncThreadLock()

def create_connection(self, origin: Origin) -> AsyncConnectionInterface:
Expand All @@ -148,9 +149,12 @@ def connections(self) -> List[AsyncConnectionInterface]:
```python
>>> pool.connections
[
<AsyncHTTPConnection ['https://example.com:443', HTTP/1.1, ACTIVE, Request Count: 6]>,
<AsyncHTTPConnection ['https://example.com:443', HTTP/1.1, IDLE, Request Count: 9]> ,
<AsyncHTTPConnection ['http://example.com:80', HTTP/1.1, IDLE, Request Count: 1]>,
<AsyncHTTPConnection ['https://example.com:443', HTTP/1.1, ACTIVE,
Request Count: 6]>,
<AsyncHTTPConnection ['https://example.com:443', HTTP/1.1, IDLE,
Request Count: 9]>,
<AsyncHTTPConnection ['http://example.com:80', HTTP/1.1, IDLE,
Request Count: 1]>,
]
```
"""
Expand All @@ -160,7 +164,7 @@ async def handle_async_request(self, request: Request) -> Response:
"""
Send an HTTP request, and return an HTTP response.
This is the core implementation that is called into by `.request()` or `.stream()`.
The core implementation that is called into by `.request()` or `.stream()`.
"""
scheme = request.url.scheme.decode()
if scheme == "":
Expand Down
8 changes: 4 additions & 4 deletions httpcore/_async/http2.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,10 +470,10 @@ async def _write_outgoing_data(self, request: Request) -> None:
except Exception as exc: # pragma: nocover
# If we get a network error we should:
#
# 1. Save the exception and just raise it immediately on any future write.
# (For example, this means that a single write timeout or disconnect will
# immediately close all pending streams. Without requiring multiple
# sequential timeouts.)
# 1. Save the exception and just raise it immediately on any
# future write. (For example, this means that a single write timeout
# or disconnect will immediately close all pending streams,
# without requiring multiple sequential timeouts.)
# 2. Mark the connection as errored, so that we don't accept any other
# incoming requests.
self._write_exception = exc
Expand Down
3 changes: 2 additions & 1 deletion httpcore/_async/http_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ def __init__(
ssl_context: An SSL context to use for verifying connections.
If not specified, the default `httpcore.default_ssl_context()`
will be used.
proxy_ssl_context: The same as `ssl_context`, but for a proxy server rather than a remote origin.
proxy_ssl_context: The same as `ssl_context`, but for a proxy server
rather than a remote origin.
max_connections: The maximum number of concurrent HTTP connections that
the pool should allow. Any attempt to send a request on a pool that
would exceed this amount will block until a connection is available.
Expand Down
3 changes: 2 additions & 1 deletion httpcore/_backends/trio.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ async def start_tls(

def get_extra_info(self, info: str) -> typing.Any:
if info == "ssl_object" and isinstance(self._stream, trio.SSLStream):
# Type checkers cannot see `_ssl_object` attribute because trio._ssl.SSLStream uses __getattr__/__setattr__.
# Type checkers cannot see `_ssl_object` attribute
# because `trio._ssl.SSLStream` uses `__getattr__`/`__setattr__`.
# Tracked at https://github.com/python-trio/trio/issues/542
return self._stream._ssl_object # type: ignore[attr-defined]
if info == "client_addr":
Expand Down
3 changes: 2 additions & 1 deletion httpcore/_sync/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ def __init__(
def handle_request(self, request: Request) -> Response:
if not self.can_handle_request(request.url.origin):
raise RuntimeError(
f"Attempted to send request to {request.url.origin} on connection to {self._origin}"
f"Attempted to send request to {request.url.origin}"
f" on connection to {self._origin}"
)

try:
Expand Down
18 changes: 11 additions & 7 deletions httpcore/_sync/connection_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,10 @@ def __init__(
self._connections: List[ConnectionInterface] = []
self._requests: List[PoolRequest] = []

# We only mutate the state of the connection pool within an 'optional_thread_lock'
# context. This holds a threading lock unless we're running in async mode,
# in which case it is a no-op.
# We only mutate the state of the connection pool
# within an 'optional_thread_lock' context.
# This holds a threading lock unless we're running in
# async mode, in which case it is a no-op.
self._optional_thread_lock = ThreadLock()

def create_connection(self, origin: Origin) -> ConnectionInterface:
Expand All @@ -148,9 +149,12 @@ def connections(self) -> List[ConnectionInterface]:
```python
>>> pool.connections
[
<HTTPConnection ['https://example.com:443', HTTP/1.1, ACTIVE, Request Count: 6]>,
<HTTPConnection ['https://example.com:443', HTTP/1.1, IDLE, Request Count: 9]> ,
<HTTPConnection ['http://example.com:80', HTTP/1.1, IDLE, Request Count: 1]>,
<HTTPConnection ['https://example.com:443', HTTP/1.1, ACTIVE,
Request Count: 6]>,
<HTTPConnection ['https://example.com:443', HTTP/1.1, IDLE,
Request Count: 9]>,
<HTTPConnection ['http://example.com:80', HTTP/1.1, IDLE,
Request Count: 1]>,
]
```
"""
Expand All @@ -160,7 +164,7 @@ def handle_request(self, request: Request) -> Response:
"""
Send an HTTP request, and return an HTTP response.
This is the core implementation that is called into by `.request()` or `.stream()`.
The core implementation that is called into by `.request()` or `.stream()`.
"""
scheme = request.url.scheme.decode()
if scheme == "":
Expand Down
8 changes: 4 additions & 4 deletions httpcore/_sync/http2.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,10 +470,10 @@ def _write_outgoing_data(self, request: Request) -> None:
except Exception as exc: # pragma: nocover
# If we get a network error we should:
#
# 1. Save the exception and just raise it immediately on any future write.
# (For example, this means that a single write timeout or disconnect will
# immediately close all pending streams. Without requiring multiple
# sequential timeouts.)
# 1. Save the exception and just raise it immediately on any
# future write. (For example, this means that a single write timeout
# or disconnect will immediately close all pending streams,
# without requiring multiple sequential timeouts.)
# 2. Mark the connection as errored, so that we don't accept any other
# incoming requests.
self._write_exception = exc
Expand Down
3 changes: 2 additions & 1 deletion httpcore/_sync/http_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ def __init__(
ssl_context: An SSL context to use for verifying connections.
If not specified, the default `httpcore.default_ssl_context()`
will be used.
proxy_ssl_context: The same as `ssl_context`, but for a proxy server rather than a remote origin.
proxy_ssl_context: The same as `ssl_context`, but for a proxy server
rather than a remote origin.
max_connections: The maximum number of concurrent HTTP connections that
the pool should allow. Any attempt to send a request on a pool that
would exceed this amount will block until a connection is available.
Expand Down
21 changes: 11 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ include = [
"/httpcore",
"/CHANGELOG.md",
"/README.md",
"/tests"
"/tests",
]

[tool.hatch.metadata.hooks.fancy-pypi-readme]
Expand Down Expand Up @@ -96,26 +96,27 @@ filterwarnings = ["error"]

[tool.coverage.run]
omit = [
"venv/*",
"httpcore/_sync/*"
"venv/*",
"httpcore/_sync/*",
]
include = [
"httpcore/*",
"tests/*",
]
include = ["httpcore/*", "tests/*"]

[tool.ruff]
exclude = [
"httpcore/_sync",
"tests/_sync",
]
line-length = 88

[tool.ruff.lint]
select = [
"E",
"F",
"W",
"I"
"I",
]

[tool.ruff.pycodestyle]
max-line-length = 120

[tool.ruff.isort]
[tool.ruff.lint.isort]
combine-as-imports = true
12 changes: 6 additions & 6 deletions tests/_async/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ async def test_http_connection():
assert repr(conn) == "<AsyncHTTPConnection [CONNECTING]>"

async with conn.stream("GET", "https://example.com/") as response:
assert (
repr(conn)
== "<AsyncHTTPConnection ['https://example.com:443', HTTP/1.1, ACTIVE, Request Count: 1]>"
assert repr(conn) == (
"<AsyncHTTPConnection ['https://example.com:443', HTTP/1.1, ACTIVE,"
" Request Count: 1]>"
)
await response.aread()

Expand All @@ -55,9 +55,9 @@ async def test_http_connection():
assert not conn.is_closed()
assert conn.is_available()
assert not conn.has_expired()
assert (
repr(conn)
== "<AsyncHTTPConnection ['https://example.com:443', HTTP/1.1, IDLE, Request Count: 1]>"
assert repr(conn) == (
"<AsyncHTTPConnection ['https://example.com:443', HTTP/1.1, IDLE,"
" Request Count: 1]>"
)


Expand Down
Loading

0 comments on commit 32620a0

Please sign in to comment.