fix type hints with commonn input/output filename

Input_filename and output_filename could be None or Str. This lead
to typing issues where the static analysis type hint tool could not
check that the type colisions would not happen in runtime.

So the logic was replaced by throwing a runtime exception if either
of these valiables is ever used without first having been set.
This commit is contained in:
deeplow 2022-08-02 12:20:28 +01:00
parent 7b46d1e3cf
commit 46a62c1669
No known key found for this signature in database
GPG key ID: 577982871529A52A
2 changed files with 25 additions and 3 deletions

View file

@ -14,5 +14,27 @@ class Common(object):
def __init__(self) -> None:
# Name of input and out files
self.input_filename: Optional[str] = None
self.output_filename: Optional[str] = None
self._input_filename: Optional[str] = None
self._output_filename: Optional[str] = None
@property
def input_filename(self) -> str:
if self._input_filename is None:
raise RuntimeError("Input filename has not been set yet.")
else:
return self._input_filename
@input_filename.setter
def input_filename(self, filename: str) -> None:
self._input_filename = filename
@property
def output_filename(self) -> str:
if self._output_filename is None:
raise RuntimeError("Output filename has not been set yet.")
else:
return self._output_filename
@output_filename.setter
def output_filename(self, filename: str) -> None:
self._output_filename = filename

View file

@ -471,7 +471,7 @@ class SettingsWidget(QtWidgets.QWidget):
self.save_lineedit.setText(os.path.basename(self.common.output_filename))
def start_button_clicked(self) -> None:
if self.common.output_filename is None:
if self.save_checkbox.checkState() == QtCore.Qt.Unchecked:
# If not saving, then save it to a temp file instead
tmp = tempfile.mkstemp(suffix=".pdf", prefix="dangerzone_")
self.common.output_filename = tmp[1]