Skip to content

Commit 563dd7f

Browse files
authored
PYCO-60: Cleanup TODOs (#4)
Changes ------- * Address remaining TODOs with either log message, PYCO ticket or remove
1 parent 12894be commit 563dd7f

15 files changed

Lines changed: 28 additions & 65 deletions

File tree

acouchbase_analytics/protocol/_core/anyio_utils.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ def current_async_library() -> Optional[AsyncBackend]:
5252
except ImportError:
5353
async_lib = 'asyncio'
5454

55-
# TODO: This helps make tests work.
56-
# Should we work through the scenario when sniffio cannot find the async library?
5755
try:
5856
async_lib = sniffio.current_async_library()
5957
except sniffio.AsyncLibraryNotFoundError:
@@ -62,7 +60,7 @@ def current_async_library() -> Optional[AsyncBackend]:
6260
if async_lib not in ('asyncio', 'trio'):
6361
raise RuntimeError('Running under an unsupported async environment.')
6462

65-
# TODO: confirm trio support
63+
# TODO(PYCO-71): Add trio support
6664
if async_lib == 'trio':
6765
raise RuntimeError('trio currently not supported')
6866

acouchbase_analytics/protocol/_core/async_json_stream.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ async def _process_token_stream(self) -> None:
136136
try:
137137
_, event, value = await self._json_stream_parser.__anext__() # type: ignore[attr-defined]
138138
# this is a hack b/c the ijson.parse_async iterator does not yield to the event loop
139-
# TODO: create PYCO to either build custom JSON parsing, or dig into ijson root cause
139+
# TODO(PYCO-74): create PYCO to either build custom JSON parsing, or dig into ijson root cause
140140
await self._json_token_parser.parse_token(event, value)
141141
except StopAsyncIteration:
142142
self._token_stream_exhausted = True

acouchbase_analytics/protocol/_core/net_utils.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@ async def get_request_ip_async(host: str, port: int, logger_handler: Optional[Ca
3434
except ValueError:
3535
ip = None
3636

37-
# if we have localhost, httpx does not seem to be able to resolve IPv6 localhost (::1) properly
38-
# TODO: IPv6 support for localhost??
39-
if host == 'localhost':
40-
ip = '127.0.0.1'
41-
4237
if not ip:
4338
result = await anyio.getaddrinfo(host, port, type=socket.SOCK_STREAM, family=socket.AF_UNSPEC)
4439
res_ip = choice([addr[4][0] for addr in result]) # nosec B311

acouchbase_analytics/protocol/_core/request_context.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@
2929

3030

3131
class AsyncRequestContext:
32-
# TODO: AsyncExitStack??
33-
# https://anyio.readthedocs.io/en/stable/cancellation.html
34-
3532
def __init__(
3633
self,
3734
client_adapter: _AsyncClientAdapter,
@@ -192,7 +189,6 @@ async def _trace_handler(self, event_name: str, _: str) -> None:
192189
self._cancel_scope_deadline_updated = True
193190

194191
def _update_cancel_scope_deadline(self, deadline: float, is_absolute: Optional[bool] = False) -> None:
195-
# TODO: confirm scenario of get_time() < self._taskgroup.cancel_scope.deadline is handled by anyio
196192
new_deadline = deadline if is_absolute else get_time() + deadline
197193
current_time = get_time()
198194
if current_time >= new_deadline:
@@ -235,10 +231,6 @@ def create_response_task(self, fn: Callable[..., Coroutine[Any, Any, Any]], *arg
235231
raise RuntimeError('Async backend loop is not initialized.')
236232
task_name = f'{self._id}-response-task'
237233
task: Task[Any] = self._backend.loop.create_task(fn(*args), name=task_name)
238-
# TODO: Confirm if callback is useful/necessary;
239-
# def task_done(t: Task[Any]) -> None:
240-
# print(f'Task done callback task=({t.get_name()}); done: {t.done()}, cancelled: {t.cancelled()}')
241-
# task.add_done_callback(task_done)
242234
self._response_task = task
243235
return task
244236

@@ -416,7 +408,7 @@ async def shutdown(
416408

417409
def start_stream(self, core_response: HttpCoreResponse) -> None:
418410
if hasattr(self, '_json_stream'):
419-
# TODO: logging; I don't think this is an error...
411+
self.log_message('JSON stream already exists', LogLevel.WARNING)
420412
return
421413

422414
self._json_stream = AsyncJsonStream(
@@ -437,6 +429,7 @@ async def __aenter__(self) -> AsyncRequestContext:
437429
await self._taskgroup.__aenter__()
438430
return self
439431

432+
# TODO(PYCO-72): Possible improvement to handling async RequestContext.__aexit__
440433
async def __aexit__(
441434
self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], exc_tb: Optional[TracebackType]
442435
) -> Optional[bool]:
@@ -447,5 +440,4 @@ async def __aexit__(
447440
finally:
448441
self._maybe_set_request_error(exc_type, exc_val)
449442
del self._taskgroup
450-
# TODO: should we suppress here (e.g., return True)
451443
return None # noqa: B012

acouchbase_analytics/protocol/cluster.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from acouchbase_analytics.protocol._core.client_adapter import _AsyncClientAdapter
2929
from acouchbase_analytics.protocol._core.request_context import AsyncRequestContext
3030
from acouchbase_analytics.protocol.streaming import AsyncHttpStreamingResponse
31+
from couchbase_analytics.common.logging import LogLevel
3132
from couchbase_analytics.common.result import AsyncQueryResult
3233
from couchbase_analytics.protocol._core.request import _RequestBuilder
3334

@@ -92,12 +93,13 @@ async def shutdown(self) -> None:
9293
if self.has_client:
9394
await self._shutdown()
9495
else:
95-
# TODO: log warning
96-
print('Cluster does not have a connection. Ignoring')
96+
self.client_adapter.log_message('Cluster does not have a connection. Ignoring shutdown.', LogLevel.WARNING)
9797

9898
async def _execute_query(self, http_resp: AsyncHttpStreamingResponse) -> AsyncQueryResult:
9999
if not self.has_client:
100-
# TODO: add log message??
100+
self.client_adapter.log_message(
101+
'Cluster does not have a connection. Creating the client.', LogLevel.WARNING
102+
)
101103
await self._create_client()
102104
await http_resp.send_request()
103105
return AsyncQueryResult(http_resp)

acouchbase_analytics/protocol/scope.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from acouchbase_analytics.protocol._core.client_adapter import _AsyncClientAdapter
2828
from acouchbase_analytics.protocol._core.request_context import AsyncRequestContext
2929
from acouchbase_analytics.protocol.streaming import AsyncHttpStreamingResponse
30+
from couchbase_analytics.common.logging import LogLevel
3031
from couchbase_analytics.common.result import AsyncQueryResult
3132
from couchbase_analytics.protocol._core.request import _RequestBuilder
3233

@@ -63,7 +64,9 @@ async def _create_client(self) -> None:
6364

6465
async def _execute_query(self, http_resp: AsyncHttpStreamingResponse) -> AsyncQueryResult:
6566
if not self.client_adapter.has_client:
66-
# TODO: add log message??
67+
self.client_adapter.log_message(
68+
'Cluster does not have a connection. Creating the client.', LogLevel.WARNING
69+
)
6770
await self._create_client()
6871
await http_resp.send_request()
6972
return AsyncQueryResult(http_resp)

couchbase_analytics/common/_core/duration_str_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
from couchbase_analytics.common._core.utils import is_null_or_empty
2020

21-
# TODO: Apparently Go does not allow a leading decimal point without a leading zero, e.g., ".5s" is invalid.
21+
# NOTE: Apparently Go does not allow a leading decimal point without a leading zero, e.g., ".5s" is invalid.
2222
# We allowed this in the Columnar SDK due to how the C++ client parsed durations
2323
DURATION_PATTERN = re.compile(r'^([-+]?)((\d*(\.\d*)?){1}(?:ns|us|µs|μs|ms|s|m|h){1})+$')
2424
DURATION_PAIRS_PATTERN = re.compile(r'(\d*(?:\.\d*)?)(ns|us|ms|s|m|h)')

couchbase_analytics/common/_core/query.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ def build_query_metadata(json_data: Optional[Any] = None, raw_metadata: Optional
8787
'warnings': warnings,
8888
}
8989

90-
# TODO: include status in metadata?? Seems to only be populated in error scenario
9190
if 'status' in json_data:
9291
metadata['status'] = json_data.get('status', '')
9392

couchbase_analytics/common/_core/utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ def __call__(self, value: Any) -> str:
112112

113113
if isinstance(value, str):
114114
if value in (x.value for x in expected_type):
115-
# TODO: use warning -- maybe don't want to allow str representation?
116115
return value
117116
raise ValueError(f"Invalid str representation of {expected_type}. Received '{value}'.")
118117

couchbase_analytics/protocol/_core/net_utils.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ def get_request_ip(host: str, port: int, logger_handler: Optional[Callable[...,
3232
except ValueError:
3333
ip = None
3434

35-
# if we have localhost, httpx does not seem to be able to resolve IPv6 localhost (::1) properly
36-
# TODO: IPv6 support for localhost??
37-
if host == 'localhost':
38-
ip = '127.0.0.1'
39-
4035
if not ip:
4136
result = socket.getaddrinfo(host, port, type=socket.SOCK_STREAM, family=socket.AF_UNSPEC)
4237
res_ip = choice([addr[4][0] for addr in result]) # nosec B311

0 commit comments

Comments
 (0)