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