[openpgp] Fix pyright errors

This commit is contained in:
Philipp Hörist
2026-01-02 21:43:52 +01:00
parent be2d867f05
commit 99e33d9a1f
5 changed files with 35 additions and 13 deletions

View File

@@ -24,6 +24,7 @@ from pathlib import Path
import gpg
from gpg.errors import KeyNotFound
from gpg.results import GenkeyResult
from gpg.results import ImportResult
from nbxmpp.protocol import JID
@@ -64,12 +65,15 @@ class GPGMe(BasePGPBackend):
def generate_key(self) -> None:
with self._get_context() as context:
result = context.create_key(
f"xmpp:{self._jid}",
algorithm="default",
expires=False,
passphrase=None,
force=False,
result = cast(
GenkeyResult,
context.create_key(
f"xmpp:{self._jid}",
algorithm="default",
expires=False,
passphrase=None,
force=False,
),
)
log.info("Generated new key: %s", result.fpr)
@@ -174,6 +178,7 @@ class GPGMe(BasePGPBackend):
def import_key(self, data: bytes, jid: JID) -> KeyringItem | None:
log.info("Import key from %s", jid)
item = None
with self._get_context() as context:
result = context.key_import(data)
if not isinstance(result, ImportResult) or result.imported != 1:
@@ -183,6 +188,7 @@ class GPGMe(BasePGPBackend):
fingerprint = result.imports[0].fpr
key = self._get_key(fingerprint)
assert key is not None
item = KeyringItem(key)
if not item.is_valid(jid):
log.warning("Invalid key found")
@@ -197,4 +203,4 @@ class GPGMe(BasePGPBackend):
key = self._get_key(fingerprint)
assert key is not None
with self._get_context() as context:
context.op_delete(key, True)
context.op_delete(key, True) # pyright: ignore

View File

@@ -80,8 +80,7 @@ class ContactData:
@property
def userid(self):
if self.jid is None:
raise ValueError("JID not set")
assert self.jid is not None, "JID not set"
return "xmpp:%s" % self.jid
@property

View File

@@ -1 +1 @@
from .core import Context # noqa: F401
from .core import Context # noqa: F401 # pyright: ignore

View File

@@ -4,7 +4,6 @@ from collections.abc import Iterator
from gpg.results import DecryptResult
from gpg.results import EncryptResult
from gpg.results import Key
from gpg.results import SignResult
from gpg.results import VerifyResult

View File

@@ -50,13 +50,31 @@ class VerifyResult(Result):
is_mime: int
signatures: list[Signature]
class ImportStatus(Result): ...
class ImportStatus(Result):
fpr: str
result: int
status: int
class ImportResult(Result):
imports: ImportStatus
imported: int
imported_rsa: int
imports: list[ImportStatus]
new_revocations: int
new_signatures: int
new_sub_keys: int
new_user_ids: int
no_user_id: int
not_imported: int
secret_imported: int
secret_read: int
secret_unchanged: int
skipped_new_keys: int
skipped_v3_keys: int
unchanged: int
class GenkeyResult(Result):
_type = dict(primary=bool, sub=bool)
fpr: str
class KeylistResult(Result):
_type = dict(truncated=bool)