Skip to content

Commit d7c8ec5

Browse files
committed
chore: add function return type annotations
1 parent bc17fab commit d7c8ec5

File tree

3 files changed

+21
-19
lines changed

3 files changed

+21
-19
lines changed

wherobots/db/connection.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,19 @@ def __enter__(self):
7474
def __exit__(self, exc_type, exc_val, exc_tb):
7575
self.close()
7676

77-
def close(self):
77+
def close(self) -> None:
7878
self.__ws.close()
7979

80-
def commit(self):
80+
def commit(self) -> None:
8181
raise NotSupportedError
8282

83-
def rollback(self):
83+
def rollback(self) -> None:
8484
raise NotSupportedError
8585

8686
def cursor(self) -> Cursor:
8787
return Cursor(self.__execute_sql, self.__cancel_query)
8888

89-
def __main_loop(self):
89+
def __main_loop(self) -> None:
9090
"""Main background loop listening for messages from the SQL session."""
9191
logging.info("Starting background connection handling loop...")
9292
while self.__ws.protocol.state < websockets.protocol.State.CLOSING:
@@ -101,7 +101,7 @@ def __main_loop(self):
101101
except Exception as e:
102102
logging.exception("Error handling message from SQL session", exc_info=e)
103103

104-
def __listen(self):
104+
def __listen(self) -> None:
105105
"""Waits for the next message from the SQL session and processes it.
106106
107107
The code in this method is purposefully defensive to avoid unexpected situations killing the thread.

wherobots/db/constants.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class ExecutionState(LowercaseStrEnum):
4444
COMPLETED = auto()
4545
"The driver has completed processing the query results."
4646

47-
def is_terminal_state(self):
47+
def is_terminal_state(self) -> bool:
4848
return self in (
4949
ExecutionState.COMPLETED,
5050
ExecutionState.CANCELLED,
@@ -97,7 +97,7 @@ class AppStatus(StrEnum):
9797
DESTROY_FAILED = auto()
9898
DESTROYED = auto()
9999

100-
def is_starting(self):
100+
def is_starting(self) -> bool:
101101
return self in (
102102
AppStatus.PENDING,
103103
AppStatus.PREPARING,
@@ -107,7 +107,7 @@ def is_starting(self):
107107
AppStatus.INITIALIZING,
108108
)
109109

110-
def is_terminal_state(self):
110+
def is_terminal_state(self) -> bool:
111111
return self in (
112112
AppStatus.PREPARE_FAILED,
113113
AppStatus.DEPLOY_FAILED,

wherobots/db/cursor.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
class Cursor:
1818

19-
def __init__(self, exec_fn, cancel_fn):
19+
def __init__(self, exec_fn, cancel_fn) -> None:
2020
self.__exec_fn = exec_fn
2121
self.__cancel_fn = cancel_fn
2222

@@ -72,7 +72,7 @@ def __get_results(self) -> Optional[List[Tuple[Any, ...]]]:
7272

7373
return self.__results
7474

75-
def execute(self, operation: str, parameters: dict[str, Any] = None):
75+
def execute(self, operation: str, parameters: dict[str, Any] = None) -> None:
7676
if self.__current_execution_id:
7777
self.__cancel_fn(self.__current_execution_id)
7878

@@ -84,38 +84,40 @@ def execute(self, operation: str, parameters: dict[str, Any] = None):
8484
sql = operation.format(**(parameters or {}))
8585
self.__current_execution_id = self.__exec_fn(sql, self.__on_execution_result)
8686

87-
def executemany(self, operation: str, seq_of_parameters: list[dict[str, Any]]):
87+
def executemany(
88+
self, operation: str, seq_of_parameters: list[dict[str, Any]]
89+
) -> None:
8890
raise NotImplementedError
8991

90-
def fetchone(self):
92+
def fetchone(self) -> Any:
9193
results = self.__get_results()[self.__current_row :]
9294
if len(results) == 0:
9395
return None
9496
self.__current_row += 1
9597
return results[0]
9698

97-
def fetchmany(self, size: int = None):
99+
def fetchmany(self, size: int = None) -> list[Any]:
98100
size = size or self.arraysize
99101
results = self.__get_results()[self.__current_row : self.__current_row + size]
100102
self.__current_row += size
101103
return results
102104

103-
def fetchall(self):
105+
def fetchall(self) -> list[Any]:
104106
return self.__get_results()[self.__current_row :]
105107

106-
def close(self):
108+
def close(self) -> None:
107109
"""Close the cursor."""
108110
if self.__results is None and self.__current_execution_id:
109111
self.__cancel_fn(self.__current_execution_id)
110112

111-
def __iter__(self):
113+
def __iter__(self) -> Cursor:
112114
return self
113115

114-
def __next__(self):
116+
def __next__(self) -> None:
115117
raise StopIteration
116118

117-
def __enter__(self):
119+
def __enter__(self) -> Cursor:
118120
return self
119121

120-
def __exit__(self, exc_type, exc_val, exc_tb):
122+
def __exit__(self, exc_type, exc_val, exc_tb) -> None:
121123
self.close()

0 commit comments

Comments
 (0)