From 250230e763721315b9a34c2e5463024c43e9d82e Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Fri, 17 Oct 2025 08:48:27 +0200 Subject: [PATCH] Avoid deprecated typing.Callable. (#959) --- plugins/filter/gpg_fingerprint.py | 4 ++-- plugins/filter/openssl_csr_info.py | 3 ++- plugins/filter/openssl_privatekey_info.py | 3 ++- plugins/filter/openssl_publickey_info.py | 3 ++- plugins/filter/parse_serial.py | 4 ++-- plugins/filter/split_pem.py | 4 ++-- plugins/filter/to_serial.py | 4 ++-- plugins/filter/x509_certificate_info.py | 3 ++- plugins/filter/x509_crl_info.py | 3 ++- plugins/module_utils/_acme/certificate.py | 3 ++- plugins/module_utils/_acme/orders.py | 3 ++- plugins/module_utils/_acme/utils.py | 3 ++- .../_crypto/module_backends/privatekey_info.py | 3 ++- .../module_utils/_openssh/backends/common.py | 17 +++++++++-------- .../plugins/module_utils/_acme/test_errors.py | 7 ++++--- 15 files changed, 39 insertions(+), 28 deletions(-) diff --git a/plugins/filter/gpg_fingerprint.py b/plugins/filter/gpg_fingerprint.py index 54ee300e..ab8342dd 100644 --- a/plugins/filter/gpg_fingerprint.py +++ b/plugins/filter/gpg_fingerprint.py @@ -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, } diff --git a/plugins/filter/openssl_csr_info.py b/plugins/filter/openssl_csr_info.py index 1f8388dd..9f910792 100644 --- a/plugins/filter/openssl_csr_info.py +++ b/plugins/filter/openssl_csr_info.py @@ -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, } diff --git a/plugins/filter/openssl_privatekey_info.py b/plugins/filter/openssl_privatekey_info.py index ad718267..6b1b7566 100644 --- a/plugins/filter/openssl_privatekey_info.py +++ b/plugins/filter/openssl_privatekey_info.py @@ -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, } diff --git a/plugins/filter/openssl_publickey_info.py b/plugins/filter/openssl_publickey_info.py index bafbe23b..721addf6 100644 --- a/plugins/filter/openssl_publickey_info.py +++ b/plugins/filter/openssl_publickey_info.py @@ -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, } diff --git a/plugins/filter/parse_serial.py b/plugins/filter/parse_serial.py index 87bbbdae..9eb403c0 100644 --- a/plugins/filter/parse_serial.py +++ b/plugins/filter/parse_serial.py @@ -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, } diff --git a/plugins/filter/split_pem.py b/plugins/filter/split_pem.py index 3311140e..cba3cd63 100644 --- a/plugins/filter/split_pem.py +++ b/plugins/filter/split_pem.py @@ -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, } diff --git a/plugins/filter/to_serial.py b/plugins/filter/to_serial.py index f790fc04..6aea306a 100644 --- a/plugins/filter/to_serial.py +++ b/plugins/filter/to_serial.py @@ -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, } diff --git a/plugins/filter/x509_certificate_info.py b/plugins/filter/x509_certificate_info.py index 8519e382..a7e84ffd 100644 --- a/plugins/filter/x509_certificate_info.py +++ b/plugins/filter/x509_certificate_info.py @@ -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, } diff --git a/plugins/filter/x509_crl_info.py b/plugins/filter/x509_crl_info.py index 5b5430a2..aa5f9573 100644 --- a/plugins/filter/x509_crl_info.py +++ b/plugins/filter/x509_crl_info.py @@ -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, } diff --git a/plugins/module_utils/_acme/certificate.py b/plugins/module_utils/_acme/certificate.py index 8cfa0894..399cb7aa 100644 --- a/plugins/module_utils/_acme/certificate.py +++ b/plugins/module_utils/_acme/certificate.py @@ -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 = [] diff --git a/plugins/module_utils/_acme/orders.py b/plugins/module_utils/_acme/orders.py index d5421d13..554b7ce6 100644 --- a/plugins/module_utils/_acme/orders.py +++ b/plugins/module_utils/_acme/orders.py @@ -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: diff --git a/plugins/module_utils/_acme/utils.py b/plugins/module_utils/_acme/utils.py index 4f277c76..c9f3aae9 100644 --- a/plugins/module_utils/_acme/utils.py +++ b/plugins/module_utils/_acme/utils.py @@ -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. diff --git a/plugins/module_utils/_crypto/module_backends/privatekey_info.py b/plugins/module_utils/_crypto/module_backends/privatekey_info.py index a07e33bd..88b7afe9 100644 --- a/plugins/module_utils/_crypto/module_backends/privatekey_info.py +++ b/plugins/module_utils/_crypto/module_backends/privatekey_info.py @@ -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 diff --git a/plugins/module_utils/_openssh/backends/common.py b/plugins/module_utils/_openssh/backends/common.py index eb0f1141..d6543741 100644 --- a/plugins/module_utils/_openssh/backends/common.py +++ b/plugins/module_utils/_openssh/backends/common.py @@ -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: diff --git a/tests/unit/plugins/module_utils/_acme/test_errors.py b/tests/unit/plugins/module_utils/_acme/test_errors.py index 6138ef90..7d5b2573 100644 --- a/tests/unit/plugins/module_utils/_acme/test_errors.py +++ b/tests/unit/plugins/module_utils/_acme/test_errors.py @@ -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: