Avoid deprecated typing.Callable. (#959)

This commit is contained in:
Felix Fontein
2025-10-17 08:48:27 +02:00
committed by GitHub
parent bd5f3b4c7c
commit 250230e763
15 changed files with 39 additions and 28 deletions

View File

@@ -39,7 +39,7 @@ _value:
type: string
"""
import typing as t
from collections.abc import Callable
from ansible.errors import AnsibleFilterError
from ansible.module_utils.common.text.converters import to_bytes
@@ -70,7 +70,7 @@ def gpg_fingerprint(gpg_key_content: str | bytes) -> str:
class FilterModule:
"""Ansible jinja2 filters"""
def filters(self) -> dict[str, t.Callable]:
def filters(self) -> dict[str, Callable]:
return {
"gpg_fingerprint": gpg_fingerprint,
}

View File

@@ -275,6 +275,7 @@ _value:
"""
import typing as t
from collections.abc import Callable
from ansible.errors import AnsibleFilterError
from ansible.module_utils.common.text.converters import to_bytes, to_text
@@ -322,7 +323,7 @@ def openssl_csr_info_filter(
class FilterModule:
"""Ansible jinja2 filters"""
def filters(self) -> dict[str, t.Callable]:
def filters(self) -> dict[str, Callable]:
return {
"openssl_csr_info": openssl_csr_info_filter,
}

View File

@@ -147,6 +147,7 @@ _value:
"""
import typing as t
from collections.abc import Callable
from ansible.errors import AnsibleFilterError
from ansible.module_utils.common.text.converters import to_bytes, to_text
@@ -202,7 +203,7 @@ def openssl_privatekey_info_filter(
class FilterModule:
"""Ansible jinja2 filters"""
def filters(self) -> dict[str, t.Callable]:
def filters(self) -> dict[str, Callable]:
return {
"openssl_privatekey_info": openssl_privatekey_info_filter,
}

View File

@@ -124,6 +124,7 @@ _value:
"""
import typing as t
from collections.abc import Callable
from ansible.errors import AnsibleFilterError
from ansible.module_utils.common.text.converters import to_bytes
@@ -159,7 +160,7 @@ def openssl_publickey_info_filter(data: str | bytes) -> dict[str, t.Any]:
class FilterModule:
"""Ansible jinja2 filters"""
def filters(self) -> dict[str, t.Callable]:
def filters(self) -> dict[str, Callable]:
return {
"openssl_publickey_info": openssl_publickey_info_filter,
}

View File

@@ -39,7 +39,7 @@ _value:
type: int
"""
import typing as t
from collections.abc import Callable
from ansible.errors import AnsibleFilterError
from ansible.module_utils.common.text.converters import to_text
@@ -63,7 +63,7 @@ def parse_serial_filter(serial_str: str | bytes) -> int:
class FilterModule:
"""Ansible jinja2 filters"""
def filters(self) -> dict[str, t.Callable]:
def filters(self) -> dict[str, Callable]:
return {
"parse_serial": parse_serial_filter,
}

View File

@@ -38,7 +38,7 @@ _value:
elements: string
"""
import typing as t
from collections.abc import Callable
from ansible.errors import AnsibleFilterError
from ansible.module_utils.common.text.converters import to_text
@@ -61,7 +61,7 @@ def split_pem_filter(data: str | bytes) -> list[str]:
class FilterModule:
"""Ansible jinja2 filters"""
def filters(self) -> dict[str, t.Callable]:
def filters(self) -> dict[str, Callable]:
return {
"split_pem": split_pem_filter,
}

View File

@@ -39,7 +39,7 @@ _value:
type: string
"""
import typing as t
from collections.abc import Callable
from ansible.errors import AnsibleFilterError
@@ -64,7 +64,7 @@ def to_serial_filter(serial_int: int) -> str:
class FilterModule:
"""Ansible jinja2 filters"""
def filters(self) -> dict[str, t.Callable]:
def filters(self) -> dict[str, Callable]:
return {
"to_serial": to_serial_filter,
}

View File

@@ -309,6 +309,7 @@ _value:
"""
import typing as t
from collections.abc import Callable
from ansible.errors import AnsibleFilterError
from ansible.module_utils.common.text.converters import to_bytes, to_text
@@ -354,7 +355,7 @@ def x509_certificate_info_filter(
class FilterModule:
"""Ansible jinja2 filters"""
def filters(self) -> dict[str, t.Callable]:
def filters(self) -> dict[str, Callable]:
return {
"x509_certificate_info": x509_certificate_info_filter,
}

View File

@@ -156,6 +156,7 @@ _value:
import base64
import binascii
import typing as t
from collections.abc import Callable
from ansible.errors import AnsibleFilterError
from ansible.module_utils.common.text.converters import to_bytes, to_text
@@ -221,7 +222,7 @@ def x509_crl_info_filter(
class FilterModule:
"""Ansible jinja2 filters"""
def filters(self) -> dict[str, t.Callable]:
def filters(self) -> dict[str, Callable]:
return {
"x509_crl_info": x509_crl_info_filter,
}

View File

@@ -9,6 +9,7 @@ from __future__ import annotations
import os
import typing as t
from collections.abc import Callable
from ansible_collections.community.crypto.plugins.module_utils._acme.account import (
ACMEAccount,
@@ -213,7 +214,7 @@ class ACMECertificateClient:
self,
pending_authzs: list[Authorization],
*,
get_challenge: t.Callable[[Authorization], str],
get_challenge: Callable[[Authorization], str],
wait: bool = True,
) -> list[tuple[Authorization, str, Challenge | None]]:
authzs_with_challenges_to_wait_for = []

View File

@@ -10,6 +10,7 @@ from __future__ import annotations
import time
import typing as t
from collections.abc import Callable
from ansible_collections.community.crypto.plugins.module_utils._acme.challenges import (
Authorization,
@@ -126,7 +127,7 @@ class Order:
error_max_retries: int = 3,
replaces_cert_id: str | None = None,
profile: str | None = None,
message_callback: t.Callable[[str], None] | None = None,
message_callback: Callable[[str], None] | None = None,
) -> _Order:
"""
error_strategy can be one of the following strings:

View File

@@ -15,6 +15,7 @@ import re
import textwrap
import traceback
import typing as t
from collections.abc import Callable
from urllib.parse import unquote
from ansible_collections.community.crypto.plugins.module_utils._acme.errors import (
@@ -85,7 +86,7 @@ def pem_to_der(
def process_links(
*, info: dict[str, t.Any], callback: t.Callable[[str, str], None]
*, info: dict[str, t.Any], callback: Callable[[str, str], None]
) -> None:
"""
Process link header, calls callback for every link header with the URL and relation as options.

View File

@@ -10,6 +10,7 @@
from __future__ import annotations
import typing as t
from collections.abc import Callable
from ansible.module_utils.common.text.converters import to_bytes, to_text
@@ -131,7 +132,7 @@ def _is_cryptography_key_consistent(
*,
key_public_data: dict[str, t.Any],
key_private_data: dict[str, t.Any],
warn_func: t.Callable[[str], None] | None = None,
warn_func: Callable[[str], None] | None = None,
) -> bool | None:
if isinstance(key, cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey):
# key._backend was removed in cryptography 42.0.0

View File

@@ -12,6 +12,7 @@ import os
import stat
import traceback
import typing as t
from collections.abc import Callable
from ansible_collections.community.crypto.plugins.module_utils._openssh.utils import (
parse_openssh_version,
@@ -33,8 +34,8 @@ if t.TYPE_CHECKING:
def restore_on_failure(
f: t.Callable[t.Concatenate[AnsibleModule, str | os.PathLike, Param], None],
) -> t.Callable[t.Concatenate[AnsibleModule, str | os.PathLike, Param], None]:
f: Callable[t.Concatenate[AnsibleModule, str | os.PathLike, Param], None],
) -> Callable[t.Concatenate[AnsibleModule, str | os.PathLike, Param], None]:
def backup_and_restore(
module: AnsibleModule,
path: str | os.PathLike,
@@ -63,13 +64,13 @@ def safe_atomic_move(
def _restore_all_on_failure(
f: t.Callable[
f: Callable[
t.Concatenate[
OpensshModule, list[tuple[str | os.PathLike, str | os.PathLike]], Param
],
None,
],
) -> t.Callable[
) -> Callable[
t.Concatenate[
OpensshModule, list[tuple[str | os.PathLike, str | os.PathLike]], Param
],
@@ -149,8 +150,8 @@ class OpensshModule(metaclass=abc.ABCMeta):
@staticmethod
def skip_if_check_mode(
f: t.Callable[t.Concatenate[_OpensshModule, Param], None],
) -> t.Callable[t.Concatenate[_OpensshModule, Param], None]:
f: Callable[t.Concatenate[_OpensshModule, Param], None],
) -> Callable[t.Concatenate[_OpensshModule, Param], None]:
def wrapper(
self: _OpensshModule, *args: Param.args, **kwargs: Param.kwargs
) -> None:
@@ -161,8 +162,8 @@ class OpensshModule(metaclass=abc.ABCMeta):
@staticmethod
def trigger_change(
f: t.Callable[t.Concatenate[_OpensshModule, Param], None],
) -> t.Callable[t.Concatenate[_OpensshModule, Param], None]:
f: Callable[t.Concatenate[_OpensshModule, Param], None],
) -> Callable[t.Concatenate[_OpensshModule, Param], None]:
def wrapper(
self: _OpensshModule, *args: Param.args, **kwargs: Param.kwargs
) -> None:

View File

@@ -5,6 +5,7 @@
from __future__ import annotations
import typing as t
from collections.abc import Callable
from unittest.mock import (
MagicMock,
)
@@ -113,7 +114,7 @@ def create_error_response() -> MagicMock:
return response
def create_decode_error(msg: str) -> t.Callable[[t.Any], t.Any]:
def create_decode_error(msg: str) -> Callable[[t.Any], t.Any]:
def f(content: t.Any) -> t.NoReturn:
raise Exception(msg)
@@ -121,7 +122,7 @@ def create_decode_error(msg: str) -> t.Callable[[t.Any], t.Any]:
TEST_ACME_PROTOCOL_EXCEPTION: list[
tuple[dict[str, t.Any], t.Callable[[t.Any], t.Any] | None, str, dict[str, t.Any]]
tuple[dict[str, t.Any], Callable[[t.Any], t.Any] | None, str, dict[str, t.Any]]
] = [
(
{},
@@ -351,7 +352,7 @@ TEST_ACME_PROTOCOL_EXCEPTION: list[
)
def test_acme_protocol_exception(
parameters: dict[str, t.Any],
from_json: t.Callable[[t.Any], t.NoReturn] | None,
from_json: Callable[[t.Any], t.NoReturn] | None,
msg: str,
args: dict[str, t.Any],
) -> None: