From 14a968a608535a82b6593f5f031fab0119a9b132 Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Sat, 29 Nov 2025 00:10:47 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=AA=20Fix=20types=20@=20`ansible.galax?= =?UTF-8?q?y.collection.gpg`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Most of this patch is coversion from comments to native syntax. It also includes fixing a strict optional violation. --- lib/ansible/galaxy/collection/gpg.py | 24 +++++++++++++------- test/sanity/code-smell/mypy/ansible-core.ini | 3 +++ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/lib/ansible/galaxy/collection/gpg.py b/lib/ansible/galaxy/collection/gpg.py index 9d41cdcde8c..55a9c10347f 100644 --- a/lib/ansible/galaxy/collection/gpg.py +++ b/lib/ansible/galaxy/collection/gpg.py @@ -21,7 +21,10 @@ if t.TYPE_CHECKING: from ansible.utils.display import Display -def get_signature_from_source(source, display=None): # type: (str, t.Optional[Display]) -> str +def get_signature_from_source( + source: str, + display: Display | None = None, +) -> str: if display is not None: display.vvvv(f"Using signature at {source}") try: @@ -41,11 +44,11 @@ def get_signature_from_source(source, display=None): # type: (str, t.Optional[D def run_gpg_verify( - manifest_file, # type: str - signature, # type: str - keyring, # type: str - display, # type: Display -): # type: (...) -> tuple[str, int] + manifest_file: str, + signature: str, + keyring: str, + display: Display, +) -> tuple[str, int]: status_fd_read, status_fd_write = os.pipe() # running the gpg command will create the keyring if it does not exist @@ -95,7 +98,7 @@ def run_gpg_verify( return stdout, p.returncode -def parse_gpg_errors(status_out): # type: (str) -> t.Iterator[GpgBaseError] +def parse_gpg_errors(status_out: str) -> t.Iterator[GpgBaseError]: for line in status_out.splitlines(): if not line: continue @@ -129,9 +132,14 @@ class GpgBaseError(Exception): @classmethod def get_gpg_error_description(cls) -> str: """Return the current class description.""" + if cls.__doc__ is None: + raise RuntimeError( + f'{cls!r} was expected to have a docstring but it does not.', + ) + return ' '.join(cls.__doc__.split()) - def __post_init__(self): + def __post_init__(self) -> None: for field_name, field_type in inspect.get_annotations(type(self), eval_str=True).items(): super(GpgBaseError, self).__setattr__(field_name, field_type(getattr(self, field_name))) diff --git a/test/sanity/code-smell/mypy/ansible-core.ini b/test/sanity/code-smell/mypy/ansible-core.ini index 24414954c69..5ac805d5e0b 100644 --- a/test/sanity/code-smell/mypy/ansible-core.ini +++ b/test/sanity/code-smell/mypy/ansible-core.ini @@ -23,6 +23,9 @@ ignore_missing_imports = True [mypy-ansible_test.*] ignore_missing_imports = True +[mypy-ansible.galaxy.collection.gpg] +strict_optional = True + [mypy-ansible.galaxy.dependency_resolution.*] strict_optional = True