Skip to content

Commit 3f34bb0

Browse files
committed
ruff linting/formatting updates
1 parent 41d0822 commit 3f34bb0

102 files changed

Lines changed: 2928 additions & 3421 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.pre-commit-config.yaml

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ repos:
1717
- id: ruff-check
1818
types_or: [ python, pyi ]
1919
# Run the formatter.
20-
# - id: ruff-format
21-
# types_or: [ python, pyi ]
22-
# Compile requirements
20+
- id: ruff-format
21+
types_or: [ python, pyi ]
2322
- repo: https://github.com/PyCQA/bandit
2423
rev: 1.8.6
2524
hooks:
@@ -35,24 +34,6 @@ repos:
3534
[
3635
--quiet
3736
]
38-
- repo: https://github.com/PyCQA/isort
39-
rev: 5.13.2
40-
hooks:
41-
- id: isort
42-
exclude: |
43-
(?x)^(
44-
deps/|
45-
src/
46-
)
47-
args:
48-
[
49-
"--multi-line 1",
50-
"--force-grid-wrap 3",
51-
"--use-parentheses True",
52-
"--ensure-newline-before-comments True",
53-
"--line-length 120",
54-
"--order-by-type True"
55-
]
5637
- repo: local
5738
hooks:
5839
- id: mypy

acouchbase_analytics/__init__.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ class _LoopValidator:
2626
**INTERNAL**
2727
"""
2828

29-
REQUIRED_METHODS = {'add_reader', 'remove_reader',
30-
'add_writer', 'remove_writer'}
29+
REQUIRED_METHODS = {'add_reader', 'remove_reader', 'add_writer', 'remove_writer'}
3130

3231
@staticmethod
3332
def _get_working_loop() -> AbstractEventLoop:
@@ -53,8 +52,7 @@ def _is_valid_loop(evloop: Optional[AbstractEventLoop] = None) -> bool:
5352
if not evloop:
5453
return False
5554
for meth in _LoopValidator.REQUIRED_METHODS:
56-
abs_meth, actual_meth = (
57-
getattr(asyncio.AbstractEventLoop, meth), getattr(evloop.__class__, meth))
55+
abs_meth, actual_meth = (getattr(asyncio.AbstractEventLoop, meth), getattr(evloop.__class__, meth))
5856
if abs_meth == actual_meth:
5957
return False
6058
return True

acouchbase_analytics/cluster.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616
from __future__ import annotations
1717

1818
import sys
19-
from typing import (TYPE_CHECKING,
20-
Awaitable,
21-
Optional)
19+
from typing import TYPE_CHECKING, Awaitable, Optional
2220

2321
if sys.version_info < (3, 10):
2422
from typing_extensions import TypeAlias
@@ -56,12 +54,11 @@ class AsyncCluster:
5654
5755
""" # noqa: E501
5856

59-
def __init__(self,
60-
connstr: str,
61-
credential: Credential,
62-
options: Optional[ClusterOptions] = None,
63-
**kwargs: object) -> None:
57+
def __init__(
58+
self, connstr: str, credential: Credential, options: Optional[ClusterOptions] = None, **kwargs: object
59+
) -> None:
6460
from acouchbase_analytics.protocol.cluster import AsyncCluster as _AsyncCluster
61+
6562
self._impl = _AsyncCluster(connstr, credential, options, **kwargs)
6663

6764
def database(self, name: str) -> AsyncDatabase:
@@ -157,11 +154,9 @@ def shutdown(self) -> None:
157154
return self._impl.shutdown()
158155

159156
@classmethod
160-
def create_instance(cls,
161-
connstr: str,
162-
credential: Credential,
163-
options: Optional[ClusterOptions] = None,
164-
**kwargs: object) -> AsyncCluster:
157+
def create_instance(
158+
cls, connstr: str, credential: Credential, options: Optional[ClusterOptions] = None, **kwargs: object
159+
) -> AsyncCluster:
165160
"""Create an AsyncCluster instance
166161
167162
Args:

acouchbase_analytics/cluster.pyi

Lines changed: 27 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -23,96 +23,59 @@ else:
2323

2424
from acouchbase_analytics.database import AsyncDatabase
2525
from couchbase_analytics.credential import Credential
26-
from couchbase_analytics.options import (ClusterOptions,
27-
ClusterOptionsKwargs,
28-
QueryOptions,
29-
QueryOptionsKwargs)
26+
from couchbase_analytics.options import ClusterOptions, ClusterOptionsKwargs, QueryOptions, QueryOptionsKwargs
3027
from couchbase_analytics.result import AsyncQueryResult
3128

3229
class AsyncCluster:
3330
@overload
3431
def __init__(self, http_endpoint: str, credential: Credential) -> None: ...
35-
3632
@overload
37-
def __init__(self,
38-
http_endpoint: str,
39-
credential: Credential,
40-
options: ClusterOptions) -> None: ...
41-
33+
def __init__(self, http_endpoint: str, credential: Credential, options: ClusterOptions) -> None: ...
4234
@overload
43-
def __init__(self,
44-
http_endpoint: str,
45-
credential: Credential,
46-
**kwargs: Unpack[ClusterOptionsKwargs]) -> None: ...
47-
35+
def __init__(self, http_endpoint: str, credential: Credential, **kwargs: Unpack[ClusterOptionsKwargs]) -> None: ...
4836
@overload
49-
def __init__(self,
50-
http_endpoint: str,
51-
credential: Credential,
52-
options: ClusterOptions,
53-
**kwargs: Unpack[ClusterOptionsKwargs]) -> None: ...
54-
37+
def __init__(
38+
self,
39+
http_endpoint: str,
40+
credential: Credential,
41+
options: ClusterOptions,
42+
**kwargs: Unpack[ClusterOptionsKwargs],
43+
) -> None: ...
5544
def database(self, database_name: str) -> AsyncDatabase: ...
56-
5745
@overload
5846
def execute_query(self, statement: str) -> Awaitable[AsyncQueryResult]: ...
59-
6047
@overload
6148
def execute_query(self, statement: str, options: QueryOptions) -> Awaitable[AsyncQueryResult]: ...
62-
6349
@overload
6450
def execute_query(self, statement: str, **kwargs: Unpack[QueryOptionsKwargs]) -> Awaitable[AsyncQueryResult]: ...
65-
6651
@overload
67-
def execute_query(self,
68-
statement: str,
69-
options: QueryOptions,
70-
**kwargs: Unpack[QueryOptionsKwargs]) -> Awaitable[AsyncQueryResult]: ...
71-
52+
def execute_query(
53+
self, statement: str, options: QueryOptions, **kwargs: Unpack[QueryOptionsKwargs]
54+
) -> Awaitable[AsyncQueryResult]: ...
7255
@overload
73-
def execute_query(self,
74-
statement: str,
75-
options: QueryOptions,
76-
*args: str,
77-
**kwargs: Unpack[QueryOptionsKwargs]) -> Awaitable[AsyncQueryResult]: ...
78-
56+
def execute_query(
57+
self, statement: str, options: QueryOptions, *args: str, **kwargs: Unpack[QueryOptionsKwargs]
58+
) -> Awaitable[AsyncQueryResult]: ...
7959
@overload
80-
def execute_query(self,
81-
statement: str,
82-
options: QueryOptions,
83-
*args: str,
84-
**kwargs: str) -> Awaitable[AsyncQueryResult]: ...
85-
60+
def execute_query(
61+
self, statement: str, options: QueryOptions, *args: str, **kwargs: str
62+
) -> Awaitable[AsyncQueryResult]: ...
8663
@overload
87-
def execute_query(self,
88-
statement: str,
89-
*args: str,
90-
**kwargs: str) -> Awaitable[AsyncQueryResult]: ...
91-
64+
def execute_query(self, statement: str, *args: str, **kwargs: str) -> Awaitable[AsyncQueryResult]: ...
9265
def shutdown(self) -> None: ...
93-
9466
@overload
9567
@classmethod
9668
def create_instance(cls, http_endpoint: str, credential: Credential) -> AsyncCluster: ...
97-
9869
@overload
9970
@classmethod
100-
def create_instance(cls,
101-
http_endpoint: str,
102-
credential: Credential,
103-
options: ClusterOptions) -> AsyncCluster: ...
104-
71+
def create_instance(cls, http_endpoint: str, credential: Credential, options: ClusterOptions) -> AsyncCluster: ...
10572
@overload
10673
@classmethod
107-
def create_instance(cls,
108-
http_endpoint: str,
109-
credential: Credential,
110-
**kwargs: Unpack[ClusterOptionsKwargs]) -> AsyncCluster: ...
111-
74+
def create_instance(
75+
cls, http_endpoint: str, credential: Credential, **kwargs: Unpack[ClusterOptionsKwargs]
76+
) -> AsyncCluster: ...
11277
@overload
11378
@classmethod
114-
def create_instance(cls,
115-
http_endpoint: str,
116-
credential: Credential,
117-
options: ClusterOptions,
118-
**kwargs: Unpack[ClusterOptionsKwargs]) -> AsyncCluster: ...
79+
def create_instance(
80+
cls, http_endpoint: str, credential: Credential, options: ClusterOptions, **kwargs: Unpack[ClusterOptionsKwargs]
81+
) -> AsyncCluster: ...

acouchbase_analytics/database.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,13 @@
3232
class AsyncDatabase:
3333
def __init__(self, cluster: AsyncCluster, database_name: str) -> None:
3434
from acouchbase_analytics.protocol.database import AsyncDatabase as _AsyncDatabase
35+
3536
self._impl = _AsyncDatabase(cluster, database_name)
3637

3738
@property
3839
def name(self) -> str:
3940
"""
40-
str: The name of this :class:`~acouchbase_analytics.database.AsyncDatabase` instance.
41+
str: The name of this :class:`~acouchbase_analytics.database.AsyncDatabase` instance.
4142
"""
4243
return self._impl.name
4344

acouchbase_analytics/database.pyi

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ from acouchbase_analytics.scope import AsyncScope
1818

1919
class AsyncDatabase:
2020
def __init__(self, cluster: AsyncCluster, database_name: str) -> None: ...
21-
2221
@property
2322
def name(self) -> str: ...
24-
2523
def scope(self, scope_name: str) -> AsyncScope: ...

acouchbase_analytics/protocol/_core/anyio_utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ def get_time() -> float:
1212
"""
1313
return anyio.current_time()
1414

15+
1516
async def sleep(delay: float) -> None:
1617
await anyio.sleep(delay)
1718

19+
1820
class AsyncBackend:
1921
def __init__(self, backend_lib: str) -> None:
2022
"""
@@ -35,13 +37,15 @@ def loop(self) -> Optional[AbstractEventLoop]:
3537
Get the event loop for the async backend, if it exists
3638
"""
3739
if not hasattr(self, '_loop'):
38-
if self._backend_lib == 'asyncio':
40+
if self._backend_lib == 'asyncio':
3941
import asyncio
42+
4043
self._loop = asyncio.get_event_loop()
4144
else:
4245
raise RuntimeError('Unsupported async backend library.')
4346
return self._loop
4447

48+
4549
def current_async_library() -> Optional[AsyncBackend]:
4650
try:
4751
import sniffio

acouchbase_analytics/protocol/_core/async_json_stream.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,20 @@
1818
from typing import AsyncIterator, Optional
1919

2020
import ijson
21-
from anyio import (EndOfStream,
22-
Event,
23-
create_memory_object_stream)
21+
from anyio import EndOfStream, Event, create_memory_object_stream
2422

2523
from acouchbase_analytics.protocol._core.async_json_token_parser import AsyncJsonTokenParser
26-
from couchbase_analytics.common._core.json_parsing import (JsonStreamConfig,
27-
ParsedResult,
28-
ParsedResultType)
24+
from couchbase_analytics.common._core.json_parsing import JsonStreamConfig, ParsedResult, ParsedResultType
2925
from couchbase_analytics.common.errors import AnalyticsError
3026

3127

3228
class AsyncJsonStream:
33-
def __init__(self,
34-
http_stream_iter: AsyncIterator[bytes],
35-
*,
36-
stream_config: Optional[JsonStreamConfig]=None,
37-
) -> None:
29+
def __init__(
30+
self,
31+
http_stream_iter: AsyncIterator[bytes],
32+
*,
33+
stream_config: Optional[JsonStreamConfig] = None,
34+
) -> None:
3835
# HTTP stream handling
3936
if stream_config is None:
4037
stream_config = JsonStreamConfig()
@@ -44,7 +41,9 @@ def __init__(self,
4441
self._http_stream_exhausted = False
4542

4643
# results handling
47-
self._send_stream, self._receive_stream = create_memory_object_stream[ParsedResult](max_buffer_size=stream_config.buffered_row_max) # noqa: E501
44+
self._send_stream, self._receive_stream = create_memory_object_stream[ParsedResult](
45+
max_buffer_size=stream_config.buffered_row_max
46+
) # noqa: E501
4847
self._json_stream_parser = None
4948
self._buffer_entire_result = stream_config.buffer_entire_result
5049
handler = None if self._buffer_entire_result is True else self._handle_json_result
@@ -88,7 +87,7 @@ def _continue_processing(self) -> bool:
8887
return False
8988
return True
9089

91-
async def _send_to_stream(self, result: ParsedResult, close: Optional[bool]=False) -> None:
90+
async def _send_to_stream(self, result: ParsedResult, close: Optional[bool] = False) -> None:
9291
"""
9392
**INTERNAL**
9493
"""
@@ -104,7 +103,7 @@ async def _handle_json_result(self, row: bytes) -> None:
104103
self._handle_notification(ParsedResultType.ROW)
105104
await self._send_to_stream(ParsedResult(row, ParsedResultType.ROW))
106105

107-
def _handle_notification(self, result_type: Optional[ParsedResultType]=None) -> None:
106+
def _handle_notification(self, result_type: Optional[ParsedResultType] = None) -> None:
108107
if self._has_results_or_errors_evt.is_set():
109108
return
110109

@@ -121,7 +120,7 @@ async def _process_token_stream(self) -> None:
121120
**INTERNAL**
122121
"""
123122
if self._json_stream_parser is None:
124-
self._json_stream_parser = ijson.parse_async(self, buf_size=self._http_stream_buffer_size)
123+
self._json_stream_parser = ijson.parse_async(self, buf_size=self._http_stream_buffer_size)
125124

126125
while self._continue_processing():
127126
try:
@@ -138,13 +137,12 @@ async def _process_token_stream(self) -> None:
138137
self._handle_notification(ParsedResultType.ERROR)
139138
return
140139

141-
142140
if self._token_stream_exhausted:
143141
result_type = ParsedResultType.ERROR if self._json_token_parser.has_errors else ParsedResultType.END
144142
await self._send_to_stream(ParsedResult(self._json_token_parser.get_result(), result_type), close=True)
145143
self._handle_notification(result_type)
146144

147-
async def read(self, size: Optional[int]=-1) -> bytes:
145+
async def read(self, size: Optional[int] = -1) -> bytes:
148146
"""
149147
**INTERNAL**
150148
"""

0 commit comments

Comments
 (0)