From 744f86fbc5cf1c0cdfaac66f05fb5fbec72bd7fc Mon Sep 17 00:00:00 2001 From: Martin Krizek Date: Mon, 2 Jun 2025 09:49:42 +0200 Subject: [PATCH] Deprecate module_utils.common.collections.count (#85233) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 🇺🇦 Sviatoslav Sydorenko (Святослав Сидоренко) Co-authored-by: Matt Clay (cherry picked from commit 487d69922678ce1347dcb7d73f26fef952b1229f) --- .../module_utils-common-collections-counter-deprecated.yml | 2 ++ lib/ansible/module_utils/common/collections.py | 6 ++++++ 2 files changed, 8 insertions(+) create mode 100644 changelogs/fragments/module_utils-common-collections-counter-deprecated.yml diff --git a/changelogs/fragments/module_utils-common-collections-counter-deprecated.yml b/changelogs/fragments/module_utils-common-collections-counter-deprecated.yml new file mode 100644 index 00000000000..89b0b8f3e26 --- /dev/null +++ b/changelogs/fragments/module_utils-common-collections-counter-deprecated.yml @@ -0,0 +1,2 @@ +deprecated_features: + - "The ``ansible.module_utils.common.collections.count()`` function is deprecated and will be removed in ansible-core 2.23. Use ``collections.Counter()`` from the Python standard library instead." diff --git a/lib/ansible/module_utils/common/collections.py b/lib/ansible/module_utils/common/collections.py index f5fae55aa8d..9f4dfb9b4d0 100644 --- a/lib/ansible/module_utils/common/collections.py +++ b/lib/ansible/module_utils/common/collections.py @@ -6,6 +6,7 @@ from __future__ import annotations +from ansible.module_utils.common import warnings as _warnings from ansible.module_utils.six import binary_type, text_type from ansible.module_utils.six.moves.collections_abc import Hashable, Mapping, MutableMapping, Sequence # pylint: disable=unused-import @@ -102,6 +103,11 @@ def count(seq): code is run on Python 2.6.* where collections.Counter is not available. It should be deprecated and replaced when support for Python < 2.7 is dropped. """ + _warnings.deprecate( + msg="The `ansible.module_utils.common.collections.count` function is deprecated.", + version="2.23", + help_text="Use `collections.Counter` from the Python standard library instead.", + ) if not is_iterable(seq): raise Exception('Argument provided is not an iterable') counters = dict()