diff --git a/changelogs/fragments/compat_datetime.yml b/changelogs/fragments/compat_datetime.yml new file mode 100644 index 00000000000..eba153328c0 --- /dev/null +++ b/changelogs/fragments/compat_datetime.yml @@ -0,0 +1,3 @@ +--- +removed_features: + - compat.datetime - removed deprecated datetime compat APIs (https://github.com/ansible/ansible/issues/86000). diff --git a/lib/ansible/module_utils/compat/datetime.py b/lib/ansible/module_utils/compat/datetime.py deleted file mode 100644 index 7392a753340..00000000000 --- a/lib/ansible/module_utils/compat/datetime.py +++ /dev/null @@ -1,50 +0,0 @@ -# Copyright (c) 2023 Ansible -# Simplified BSD License (see licenses/simplified_bsd.txt or https://opensource.org/licenses/BSD-2-Clause) - -from __future__ import annotations - -import datetime as _datetime -import typing as t - -from ansible.module_utils.common.warnings import deprecate - - -_UTC = _datetime.timezone.utc - - -def _utcfromtimestamp(timestamp: float) -> _datetime.datetime: - """Construct an aware UTC datetime from a POSIX timestamp.""" - return _datetime.datetime.fromtimestamp(timestamp, _UTC) - - -def _utcnow() -> _datetime.datetime: - """Construct an aware UTC datetime from time.time().""" - return _datetime.datetime.now(_UTC) - - -_deprecated_shims_map: dict[str, t.Callable[..., object] | _datetime.timezone] = { - 'UTC': _UTC, - 'utcfromtimestamp': _utcfromtimestamp, - 'utcnow': _utcnow, -} - -__all__ = tuple(_deprecated_shims_map) - - -def __getattr__(importable_name: str) -> t.Callable[..., object] | _datetime.timezone: - """Inject import-time deprecation warnings. - - Specifically, for ``UTC``, ``utcfromtimestamp()`` and ``utcnow()``. - """ - try: - importable = _deprecated_shims_map[importable_name] - except KeyError as key_err: - raise AttributeError(f"module {__name__!r} has no attribute {key_err}") from None - - deprecate( - msg=f'The `ansible.module_utils.compat.datetime.{importable_name}` ' - 'function is deprecated.', - version='2.21', - ) - - return importable diff --git a/test/sanity/ignore.txt b/test/sanity/ignore.txt index 69375faac4d..e5081746dc9 100644 --- a/test/sanity/ignore.txt +++ b/test/sanity/ignore.txt @@ -236,7 +236,6 @@ test/integration/targets/ansible-test-sanity-pylint/deprecated_thing.py pylint:a lib/ansible/module_utils/basic.py pylint:ansible-deprecated-version # TODO: 2.21 lib/ansible/module_utils/basic.py pylint:ansible-deprecated-version-comment # TODO: 2.21 lib/ansible/module_utils/common/validation.py pylint:ansible-deprecated-version # TODO: 2.21 -lib/ansible/module_utils/compat/datetime.py pylint:ansible-deprecated-version # TODO: 2.21 lib/ansible/module_utils/compat/paramiko.py pylint:ansible-deprecated-version # TODO: 2.21 lib/ansible/plugins/connection/paramiko_ssh.py pylint:ansible-deprecated-version # TODO: 2.21 lib/ansible/plugins/strategy/__init__.py pylint:ansible-deprecated-version # TODO: 2.21