I'm new to using typing and mypy.
With the below block of code, mypy complains that ret cannot be assigned None because Incompatible types in assignment (expression has type "None", variable has type "Tuple[Connection, Cursor]") (python-mypy).
def __connect__(self) -> Tuple[Optional[Tuple[Conn, Cursor]], Status]:
"""Establish DB connection."""
if self.db_type is DB_Type.SQLITE:
conn = sqlite3.connect(self.db_name)
cur = conn.cursor()
ret, status = (conn, cur), Status(Code.OK)
else:
ret, status = None, self.INVALID_STATUS # mypy error
return ret, status
But I'm defining the return type signature as Optional[Tuple[Connection, Cursor], instead of Tuple[Connection, Cursor]. So either I'm overlooking something, or there is a limitation in mypy static analysis, for which there is probably some workaround... pointers much appreciated.