diff options
author | wurstsalat <mailtrash@posteo.de> | 2022-11-29 21:29:49 +0300 |
---|---|---|
committer | wurstsalat <mailtrash@posteo.de> | 2022-11-29 21:29:49 +0300 |
commit | fae39c2c296db70bd2bfc2ea77f08c86e36edac2 (patch) | |
tree | c71abc28cb452cd78e3dbb26b750aeee86f8a5aa | |
parent | 3784c12727758691c90285400eaa05a0cd723d24 (diff) |
[acronyms] Type annotations, linting
-rw-r--r-- | acronyms_expander/__init__.py | 2 | ||||
-rw-r--r-- | acronyms_expander/acronyms_expander.py | 1 | ||||
-rw-r--r-- | acronyms_expander/gtk/config.py | 40 |
3 files changed, 33 insertions, 10 deletions
diff --git a/acronyms_expander/__init__.py b/acronyms_expander/__init__.py index 6b85dc7..7c87223 100644 --- a/acronyms_expander/__init__.py +++ b/acronyms_expander/__init__.py @@ -1 +1 @@ -from .acronyms_expander import AcronymsExpanderPlugin +from .acronyms_expander import AcronymsExpanderPlugin # type: ignore diff --git a/acronyms_expander/acronyms_expander.py b/acronyms_expander/acronyms_expander.py index 74d80a2..d9d5f2a 100644 --- a/acronyms_expander/acronyms_expander.py +++ b/acronyms_expander/acronyms_expander.py @@ -14,6 +14,7 @@ # # You should have received a copy of the GNU General Public License # along with Acronyms Expander. If not, see <http://www.gnu.org/licenses/>. + from __future__ import annotations import json diff --git a/acronyms_expander/gtk/config.py b/acronyms_expander/gtk/config.py index 7b59525..090bed0 100644 --- a/acronyms_expander/gtk/config.py +++ b/acronyms_expander/gtk/config.py @@ -14,6 +14,11 @@ # You should have received a copy of the GNU General Public License # along with Acronyms Expander. If not, see <http://www.gnu.org/licenses/>. +from __future__ import annotations + +from typing import Any +from typing import TYPE_CHECKING + from pathlib import Path from gi.repository import Gtk @@ -24,9 +29,16 @@ from gajim.common import app from gajim.plugins.plugins_i18n import _ from gajim.plugins.helpers import get_builder +if TYPE_CHECKING: + from ..acronyms_expander import AcronymsExpanderPlugin + class ConfigDialog(Gtk.ApplicationWindow): - def __init__(self, plugin, transient): + def __init__(self, + plugin: AcronymsExpanderPlugin, + transient: Gtk.Window + ) -> None: + Gtk.ApplicationWindow.__init__(self) self.set_application(app.app) self.set_show_menubar(False) @@ -38,7 +50,7 @@ class ConfigDialog(Gtk.ApplicationWindow): self.set_destroy_with_parent(True) ui_path = Path(__file__).parent - self._ui = get_builder(ui_path.resolve() / 'config.ui') + self._ui = get_builder(str(ui_path.resolve() / 'config.ui')) self._plugin = plugin @@ -50,19 +62,29 @@ class ConfigDialog(Gtk.ApplicationWindow): self._ui.connect_signals(self) self.connect('destroy', self._on_destroy) - def _fill_list(self): + def _fill_list(self) -> None: for acronym, substitute in self._plugin.acronyms.items(): self._ui.acronyms_store.append([acronym, substitute]) - def _on_acronym_edited(self, _renderer, path, new_text): + def _on_acronym_edited(self, + _renderer: Gtk.CellRendererText, + path: str, + new_text: str + ) -> None: + iter_ = self._ui.acronyms_store.get_iter(path) self._ui.acronyms_store.set_value(iter_, 0, new_text) - def _on_substitute_edited(self, _renderer, path, new_text): + def _on_substitute_edited(self, + _renderer: Gtk.CellRendererText, + path: str, + new_text: str + ) -> None: + iter_ = self._ui.acronyms_store.get_iter(path) self._ui.acronyms_store.set_value(iter_, 1, new_text) - def _on_add_clicked(self, _button): + def _on_add_clicked(self, _button: Gtk.Button) -> None: self._ui.acronyms_store.append(['', '']) row = self._ui.acronyms_store[-1] self._ui.acronyms_treeview.scroll_to_cell( @@ -70,9 +92,9 @@ class ConfigDialog(Gtk.ApplicationWindow): self._ui.selection.unselect_all() self._ui.selection.select_path(row.path) - def _on_remove_clicked(self, _button): + def _on_remove_clicked(self, _button: Gtk.Button) -> None: model, paths = self._ui.selection.get_selected_rows() - references = [] + references: list[Gtk.TreeRowReference] = [] for path in paths: references.append(Gtk.TreeRowReference.new(model, path)) @@ -80,7 +102,7 @@ class ConfigDialog(Gtk.ApplicationWindow): iter_ = model.get_iter(ref.get_path()) self._ui.acronyms_store.remove(iter_) - def _on_destroy(self, *args): + def _on_destroy(self, *args: Any) -> None: acronyms = {} for row in self._ui.acronyms_store: acronym, substitute = row |