mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 22:02:50 +00:00
Python 3.8 collections compatibility fixes.
Includes a new pylint blacklist plugin to prevent regressions.
This commit is contained in:
@@ -10,20 +10,37 @@ Third parties should not use this.
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
try:
|
||||
"""Python 3.3+ branch."""
|
||||
from collections.abc import (
|
||||
MappingView,
|
||||
ItemsView,
|
||||
KeysView,
|
||||
ValuesView,
|
||||
Mapping, MutableMapping,
|
||||
Sequence, MutableSequence,
|
||||
Set, MutableSet,
|
||||
Container,
|
||||
Hashable,
|
||||
Sized,
|
||||
Callable,
|
||||
Iterable,
|
||||
Iterator,
|
||||
)
|
||||
except ImportError:
|
||||
"""Use old lib location under 2.6-3.2."""
|
||||
from collections import (
|
||||
MappingView,
|
||||
ItemsView,
|
||||
KeysView,
|
||||
ValuesView,
|
||||
Mapping, MutableMapping,
|
||||
Sequence, MutableSequence,
|
||||
Set, MutableSet,
|
||||
Container,
|
||||
Hashable,
|
||||
Sized,
|
||||
Callable,
|
||||
Iterable,
|
||||
Iterator,
|
||||
)
|
||||
|
||||
@@ -36,6 +36,7 @@ from ansible.module_utils._text import to_text
|
||||
from ansible.module_utils.basic import env_fallback, return_values
|
||||
from ansible.module_utils.network.common.utils import to_list, ComplexList
|
||||
from ansible.module_utils.connection import Connection, ConnectionError
|
||||
from ansible.module_utils.common._collections_compat import Mapping
|
||||
from ansible.module_utils.network.common.config import NetworkConfig, dumps
|
||||
from ansible.module_utils.six import iteritems, string_types
|
||||
from ansible.module_utils.urls import fetch_url
|
||||
@@ -179,7 +180,7 @@ class Cli:
|
||||
responses = []
|
||||
try:
|
||||
resp = connection.edit_config(config, replace=replace)
|
||||
if isinstance(resp, collections.Mapping):
|
||||
if isinstance(resp, Mapping):
|
||||
resp = resp['response']
|
||||
except ConnectionError as e:
|
||||
code = getattr(e, 'code', 1)
|
||||
|
||||
@@ -43,6 +43,7 @@ except ImportError:
|
||||
from ansible.module_utils import six
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils._text import to_native
|
||||
from ansible.module_utils.common._collections_compat import Mapping
|
||||
|
||||
|
||||
def transform_list_to_dict(list_):
|
||||
@@ -59,7 +60,7 @@ def transform_list_to_dict(list_):
|
||||
return ret
|
||||
|
||||
for value in list_:
|
||||
if isinstance(value, collections.Mapping):
|
||||
if isinstance(value, Mapping):
|
||||
ret.update(value)
|
||||
else:
|
||||
ret[to_native(value, errors='surrogate_or_strict')] = True
|
||||
@@ -108,7 +109,7 @@ def merge_list_by_key(original_list, updated_list, key, ignore_when_null=None):
|
||||
|
||||
|
||||
def _str_sorted(obj):
|
||||
if isinstance(obj, collections.Mapping):
|
||||
if isinstance(obj, Mapping):
|
||||
return json.dumps(obj, sort_keys=True)
|
||||
else:
|
||||
return str(obj)
|
||||
@@ -430,7 +431,7 @@ class OneViewModuleBase(object):
|
||||
# If both values are null, empty or False it will be considered equal.
|
||||
elif not resource1[key] and not resource2[key]:
|
||||
continue
|
||||
elif isinstance(resource1[key], collections.Mapping):
|
||||
elif isinstance(resource1[key], Mapping):
|
||||
# recursive call
|
||||
if not self.compare(resource1[key], resource2[key]):
|
||||
self.module.log(self.MSG_DIFF_AT_KEY.format(key) + debug_resources)
|
||||
@@ -482,7 +483,7 @@ class OneViewModuleBase(object):
|
||||
resource2 = sorted(resource2, key=_str_sorted)
|
||||
|
||||
for i, val in enumerate(resource1):
|
||||
if isinstance(val, collections.Mapping):
|
||||
if isinstance(val, Mapping):
|
||||
# change comparison function to compare dictionaries
|
||||
if not self.compare(val, resource2[i]):
|
||||
self.module.log("resources are different. " + debug_resources)
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
import collections
|
||||
import inspect
|
||||
import os
|
||||
import time
|
||||
@@ -27,6 +26,8 @@ from abc import ABCMeta, abstractmethod
|
||||
from datetime import datetime
|
||||
from distutils.version import LooseVersion
|
||||
|
||||
from ansible.module_utils.common._collections_compat import Mapping
|
||||
|
||||
try:
|
||||
from enum import Enum # enum is a ovirtsdk4 requirement
|
||||
import ovirtsdk4 as sdk
|
||||
@@ -512,7 +513,7 @@ class BaseModule(object):
|
||||
|
||||
def diff_update(self, after, update):
|
||||
for k, v in update.items():
|
||||
if isinstance(v, collections.Mapping):
|
||||
if isinstance(v, Mapping):
|
||||
after[k] = self.diff_update(after.get(k, dict()), v)
|
||||
else:
|
||||
after[k] = update[k]
|
||||
|
||||
Reference in New Issue
Block a user