Skip to content

Commit

Permalink
Replace __future__.annotations to support static type-checking across…
Browse files Browse the repository at this point in the history
… Python versions (incl. 3.6); Fix uninitialized variable in unit-tests. (#35)
  • Loading branch information
LinZhihao-723 authored Nov 25, 2023
1 parent ce54d36 commit 72729c8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
24 changes: 12 additions & 12 deletions clp_ffi_py/ir/query_builder.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

from copy import deepcopy
from typing import List, Optional

Expand Down Expand Up @@ -51,7 +49,7 @@ def wildcard_queries(self) -> List[WildcardQuery]:
"""
return deepcopy(self._wildcard_queries)

def set_search_time_lower_bound(self, ts: int) -> QueryBuilder:
def set_search_time_lower_bound(self, ts: int) -> "QueryBuilder":
"""
:param ts: Start of the search time range (inclusive) as a UNIX epoch
timestamp in milliseconds.
Expand All @@ -60,7 +58,7 @@ def set_search_time_lower_bound(self, ts: int) -> QueryBuilder:
self._search_time_lower_bound = ts
return self

def set_search_time_upper_bound(self, ts: int) -> QueryBuilder:
def set_search_time_upper_bound(self, ts: int) -> "QueryBuilder":
"""
:param ts: End of the search time range (inclusive) as a UNIX epoch
timestamp in milliseconds.
Expand All @@ -69,7 +67,7 @@ def set_search_time_upper_bound(self, ts: int) -> QueryBuilder:
self._search_time_upper_bound = ts
return self

def set_search_time_termination_margin(self, ts: int) -> QueryBuilder:
def set_search_time_termination_margin(self, ts: int) -> "QueryBuilder":
"""
:param ts: The search time termination margin as a UNIX epoch timestamp
in milliseconds.
Expand All @@ -78,7 +76,9 @@ def set_search_time_termination_margin(self, ts: int) -> QueryBuilder:
self._search_time_termination_margin = ts
return self

def add_wildcard_query(self, wildcard_query: str, case_sensitive: bool = False) -> QueryBuilder:
def add_wildcard_query(
self, wildcard_query: str, case_sensitive: bool = False
) -> "QueryBuilder":
"""
Constructs and adds a :class:`~clp_ffi_py.wildcard_query.WildcardQuery`
to the wildcard query list.
Expand All @@ -90,7 +90,7 @@ def add_wildcard_query(self, wildcard_query: str, case_sensitive: bool = False)
self._wildcard_queries.append(WildcardQuery(wildcard_query, case_sensitive))
return self

def add_wildcard_queries(self, wildcard_queries: List[WildcardQuery]) -> QueryBuilder:
def add_wildcard_queries(self, wildcard_queries: List[WildcardQuery]) -> "QueryBuilder":
"""
Adds a list of wildcard queries to the wildcard query list.
Expand All @@ -100,7 +100,7 @@ def add_wildcard_queries(self, wildcard_queries: List[WildcardQuery]) -> QueryBu
self._wildcard_queries.extend(wildcard_queries)
return self

def reset_search_time_lower_bound(self) -> QueryBuilder:
def reset_search_time_lower_bound(self) -> "QueryBuilder":
"""
Resets the search time lower bound to the default value.
Expand All @@ -109,7 +109,7 @@ def reset_search_time_lower_bound(self) -> QueryBuilder:
self._search_time_lower_bound = Query.default_search_time_lower_bound()
return self

def reset_search_time_upper_bound(self) -> QueryBuilder:
def reset_search_time_upper_bound(self) -> "QueryBuilder":
"""
Resets the search time upper bound to the default value.
Expand All @@ -118,7 +118,7 @@ def reset_search_time_upper_bound(self) -> QueryBuilder:
self._search_time_upper_bound = Query.default_search_time_upper_bound()
return self

def reset_search_time_termination_margin(self) -> QueryBuilder:
def reset_search_time_termination_margin(self) -> "QueryBuilder":
"""
Resets the search time termination margin to the default value.
Expand All @@ -127,7 +127,7 @@ def reset_search_time_termination_margin(self) -> QueryBuilder:
self._search_time_termination_margin = Query.default_search_time_termination_margin()
return self

def reset_wildcard_queries(self) -> QueryBuilder:
def reset_wildcard_queries(self) -> "QueryBuilder":
"""
Clears the wildcard query list.
Expand All @@ -136,7 +136,7 @@ def reset_wildcard_queries(self) -> QueryBuilder:
self._wildcard_queries.clear()
return self

def reset(self) -> QueryBuilder:
def reset(self) -> "QueryBuilder":
"""
Resets all settings to their defaults.
Expand Down
6 changes: 2 additions & 4 deletions clp_ffi_py/ir/readers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

from pathlib import Path
from sys import stderr
from types import TracebackType
Expand Down Expand Up @@ -105,12 +103,12 @@ def search(self, query: Query) -> Generator[LogEvent, None, None]:
def close(self) -> None:
self.__istream.close()

def __iter__(self) -> ClpIrStreamReader:
def __iter__(self) -> "ClpIrStreamReader":
if False is self.has_metadata():
self.read_preamble()
return self

def __enter__(self) -> ClpIrStreamReader:
def __enter__(self) -> "ClpIrStreamReader":
if False is self.has_metadata():
self.read_preamble()
return self
Expand Down
2 changes: 1 addition & 1 deletion src/clp_ffi_py/ir/native/PyDecoderBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ auto PyDecoderBuffer::test_streaming(uint32_t seed) -> PyObject* {
std::vector<uint8_t> read_bytes;
bool reach_istream_end{false};
while (false == reach_istream_end) {
std::uniform_int_distribution<Py_ssize_t> distribution(1, m_buffer_size);
std::uniform_int_distribution<Py_ssize_t> distribution(1, m_read_buffer.size());
auto num_bytes_to_read{distribution(rand_generator)};
if (get_num_unconsumed_bytes() < num_bytes_to_read) {
Py_ssize_t num_bytes_read_from_istream{0};
Expand Down

0 comments on commit 72729c8

Please sign in to comment.