Skip to content

Commit 9534bd6

Browse files
committed
cleaned up the code
1 parent 06539e4 commit 9534bd6

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

python_hackrf/pyhackrf_tools/utils.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def __init__(self, dtype: type = np.complex64, use_thread: bool = False) -> None
5757

5858
if use_thread:
5959
self._run_available = True
60-
self._queue = Queue()
60+
self._queue = Queue() # type: ignore
6161
self._append_thread = Thread(target=self._append, daemon=True)
6262
self._append_thread.start()
6363

@@ -115,7 +115,7 @@ def _cleanup(self) -> None:
115115
except Exception as er:
116116
print(f'Exception during cleanup: {er}', file=sys.stderr)
117117

118-
if os.path.exists(filepath) and not self._save_file:
118+
if os.path.exists(filepath):
119119
os.remove(filepath)
120120

121121
def _register_cleanup(self) -> None:
@@ -139,11 +139,11 @@ def _append(self) -> None:
139139
self._not_empty.set()
140140

141141
if not self._run_available:
142-
break
142+
break # type: ignore
143143
else:
144144
time.sleep(.035)
145145

146-
def append(self, data: np.ndarray, chunk_size: int = 131072) -> None:
146+
def append(self, data: np.ndarray[Any, Any], chunk_size: int = 131072) -> None:
147147
if len(data) == 0:
148148
return
149149
if self._use_thread:
@@ -156,15 +156,15 @@ def append(self, data: np.ndarray, chunk_size: int = 131072) -> None:
156156
for i in range(0, len(data), chunk_elements):
157157
chunk = data[i:i + chunk_elements]
158158

159-
self._writer.write(chunk)
159+
self._writer.write(chunk) # type: ignore
160160
self._write_ptr += self._dtype_size * chunk.size
161161

162162
self._not_empty.set()
163163

164164
if not self._run_available:
165165
break
166166

167-
def get_all(self, use_memmap: bool = False, wait: bool = False, timeout: float | None = None) -> np.ndarray:
167+
def get_all(self, use_memmap: bool = False, wait: bool = False, timeout: float | None = None) -> np.ndarray[Any, Any]:
168168
with self._rlock:
169169

170170
if self._write_ptr == 0:
@@ -174,13 +174,13 @@ def get_all(self, use_memmap: bool = False, wait: bool = False, timeout: float |
174174

175175
if not use_memmap:
176176
self._reader.seek(0)
177-
result = np.frombuffer(self._reader.read(), dtype=self._dtype)
177+
result: np.ndarray[Any, Any] = np.frombuffer(self._reader.read(), dtype=self._dtype)
178178
self._reader.seek(self._read_ptr)
179179
return result
180180

181181
return np.memmap(self._temp_file, dtype=self._dtype)
182182

183-
def get_new(self, wait: bool = False, timeout: float | None = None) -> np.ndarray:
183+
def get_new(self, wait: bool = False, timeout: float | None = None) -> np.ndarray[Any, Any]:
184184
with self._rlock:
185185

186186
write_ptr = self._write_ptr
@@ -194,11 +194,11 @@ def get_new(self, wait: bool = False, timeout: float | None = None) -> np.ndarra
194194

195195
write_ptr = self._write_ptr
196196

197-
result = np.frombuffer(self._reader.read(write_ptr - self._read_ptr), dtype=self._dtype)
197+
result: np.ndarray[Any, Any] = np.frombuffer(self._reader.read(write_ptr - self._read_ptr), dtype=self._dtype)
198198
self._read_ptr = write_ptr
199199
return result
200200

201-
def get_chunk(self, num_elements: int, ring: bool = True, wait: bool = False, timeout: float | None = None) -> np.ndarray:
201+
def get_chunk(self, num_elements: int, ring: bool = True, wait: bool = False, timeout: float | None = None) -> np.ndarray[Any, Any]:
202202
with self._rlock:
203203

204204
if num_elements <= 0:
@@ -218,6 +218,8 @@ def get_chunk(self, num_elements: int, ring: bool = True, wait: bool = False, ti
218218
total_bytes = num_elements * self._dtype_size
219219
available_bytes = write_ptr - self._read_ptr
220220

221+
result: np.ndarray[Any, Any]
222+
221223
if available_bytes >= total_bytes:
222224
result = np.frombuffer(self._reader.read(total_bytes), dtype=self._dtype)
223225
self._read_ptr += total_bytes

0 commit comments

Comments
 (0)