Skip to content

Commit 8c52b36

Browse files
committed
Added None type to timeout_override
1 parent 0662b2a commit 8c52b36

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/geocompy/communication.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -415,20 +415,29 @@ def exchange(self, cmd: str) -> str:
415415
return self.receive()
416416

417417
@contextmanager
418-
def timeout_override(self, timeout: int) -> Generator[None, None, None]:
418+
def timeout_override(
419+
self,
420+
timeout: int | None
421+
) -> Generator[None, None, None]:
419422
"""
420423
Context manager that temporarily overrides connection parameters.
421424
422425
Parameters
423426
----------
424-
timeout : int
425-
Temporary timeout in seconds.
427+
timeout : int | None
428+
Temporary timeout in seconds. Set to None to wait indefinitely.
426429
427430
Returns
428431
-------
429432
Generator
430433
Context manager generator object.
431434
435+
Warning
436+
-------
437+
An indefinite timeout might leave the connection in a perpetual
438+
waiting state, if the instrument became unresponsive in the
439+
mean time (e.g. it powered off due to low battery charge).
440+
432441
Example
433442
-------
434443
@@ -449,9 +458,7 @@ def timeout_override(self, timeout: int) -> Generator[None, None, None]:
449458
saved_timeout = self._port.timeout
450459

451460
try:
452-
if timeout is not None:
453-
self._port.timeout = timeout
461+
self._port.timeout = timeout
454462
yield
455463
finally:
456-
if timeout is not None:
457-
self._port.timeout = saved_timeout
464+
self._port.timeout = saved_timeout

0 commit comments

Comments
 (0)