From 043fc120daa15cce7cd58f391b9b3fbb6cbee8d5 Mon Sep 17 00:00:00 2001 From: wurstsalat Date: Thu, 27 Feb 2025 22:59:01 +0100 Subject: [PATCH] [openpgp] Improve type annotations --- openpgp/gtk/key.py | 15 ++++++++++++--- openpgp/pgpplugin.py | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/openpgp/gtk/key.py b/openpgp/gtk/key.py index 55ef306..89ed15a 100644 --- a/openpgp/gtk/key.py +++ b/openpgp/gtk/key.py @@ -16,10 +16,14 @@ from __future__ import annotations +from typing import cast +from typing import TYPE_CHECKING + import logging import time from gi.repository import Gtk +from nbxmpp import JID from gajim.common import app from gajim.gtk.dialogs import ConfirmationDialog @@ -31,6 +35,9 @@ from gajim.plugins.plugins_i18n import _ from openpgp.modules.key_store import KeyData from openpgp.modules.util import Trust +if TYPE_CHECKING: + from openpgp.modules.openpgp import OpenPGP + log = logging.getLogger("gajim.p.openpgp.keydialog") TRUST_DATA = { @@ -42,7 +49,7 @@ TRUST_DATA = { class KeyDialog(GajimAppWindow): - def __init__(self, account: str, jid: str, transient: Gtk.Window) -> None: + def __init__(self, account: str, jid: JID, transient: Gtk.Window) -> None: GajimAppWindow.__init__( self, @@ -67,7 +74,8 @@ class KeyDialog(GajimAppWindow): self.set_child(self._scrolled) - keys = self._client.get_module("OpenPGP").get_keys(jid, only_trusted=False) + open_pgp_module = cast(OpenPGP, self._client.get_module("OpenPGP")) # type: ignore + keys = open_pgp_module.get_keys(jid, only_trusted=False) for key in keys: log.info("Load: %s", key.fingerprint) self._listbox.append(KeyRow(key, self)) @@ -134,7 +142,8 @@ class KeyRow(Gtk.ListBoxRow): def delete_fingerprint(self): def _remove(): - self.get_parent().remove(self) + listbox = cast(Gtk.ListBox, self.get_parent()) + listbox.remove(self) self.key.delete() ConfirmationDialog( diff --git a/openpgp/pgpplugin.py b/openpgp/pgpplugin.py index 478093b..2683487 100644 --- a/openpgp/pgpplugin.py +++ b/openpgp/pgpplugin.py @@ -68,7 +68,7 @@ class OpenPGPPlugin(GajimPlugin): "signed-in": (ged.PRECORE, self.signed_in), } - self.modules = [openpgp] + self.modules = [openpgp] # type: ignore self.encryption_name = ENCRYPTION_NAME self.config_dialog = None