mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-04-29 02:12:36 +02:00
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:
parent
7b46d1e3cf
commit
46a62c1669
2 changed files with 25 additions and 3 deletions
|
@ -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
|
|
@ -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]
|
||||
|
|
Loading…
Reference in a new issue