🧪 Fix types @ `ansible.galaxy.collection.gpg`

Most of this patch is coversion from comments to native syntax. It
also includes fixing a strict optional violation.
pull/86267/head
Sviatoslav Sydorenko 2 weeks ago
parent cc839f013a
commit 14a968a608
No known key found for this signature in database
GPG Key ID: 9345E8FEA89CA455

@ -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)))

@ -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

Loading…
Cancel
Save