diff options
author | Matt Clay <mclay@redhat.com> | 2021-08-11 14:47:23 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-11 17:47:23 -0400 |
commit | ce6d8a143c6d0458c548f273d8564e4c2fac209f (patch) | |
tree | 0d7d74b58ea59acbfdbc0dce7175c43d6d6956e2 | |
parent | dc6878007be61cdfd7f1b79288c6d0b81d4cf3d2 (diff) | |
download | ansible-ce6d8a143c6d0458c548f273d8564e4c2fac209f.tar.gz |
Code cleanup to prepare for pylint update. (#75475)
* user - Remove unused code.
* Replace deprecated abstractproperty decorator.
* Fix __all__ to be a tuple.
* Use a generator in subelements lookup.
* Use from import in basic.py
* Add changelog fragment.
* Fix selinux unit test.
-rw-r--r-- | changelogs/fragments/code-cleanup.yml | 6 | ||||
-rw-r--r-- | lib/ansible/module_utils/basic.py | 2 | ||||
-rw-r--r-- | lib/ansible/modules/user.py | 4 | ||||
-rw-r--r-- | lib/ansible/plugins/connection/__init__.py | 5 | ||||
-rw-r--r-- | lib/ansible/plugins/lookup/subelements.py | 2 | ||||
-rw-r--r-- | lib/ansible/utils/unicode.py | 2 | ||||
-rw-r--r-- | test/units/module_utils/basic/test_imports.py | 6 |
7 files changed, 17 insertions, 10 deletions
diff --git a/changelogs/fragments/code-cleanup.yml b/changelogs/fragments/code-cleanup.yml new file mode 100644 index 0000000000..a7a68418b7 --- /dev/null +++ b/changelogs/fragments/code-cleanup.yml @@ -0,0 +1,6 @@ +minor_changes: + - basic module_util - Clean up ``selinux`` compat import. + - subelements lookup - Use generator in instance type check. + - unicode utils - Fix ``__all__`` which was incorrectly declared as a string instead of a tuple. + - connection base - Avoid using deprecated ``@abstractproperty`` decorator. + - user module - Remove unused code. diff --git a/lib/ansible/module_utils/basic.py b/lib/ansible/module_utils/basic.py index b009b1335a..7bb2c8cdf3 100644 --- a/lib/ansible/module_utils/basic.py +++ b/lib/ansible/module_utils/basic.py @@ -73,7 +73,7 @@ except ImportError: HAVE_SELINUX = False try: - import ansible.module_utils.compat.selinux as selinux + from ansible.module_utils.compat import selinux HAVE_SELINUX = True except ImportError: pass diff --git a/lib/ansible/modules/user.py b/lib/ansible/modules/user.py index 1a72201a1a..364bf1a5fe 100644 --- a/lib/ansible/modules/user.py +++ b/lib/ansible/modules/user.py @@ -3197,12 +3197,12 @@ def main(): # deal with password expire max if user.password_expire_max: if user.user_exists(): - (rc, out, err) = user.set_password_expire_max() + user.set_password_expire_max() # deal with password expire min if user.password_expire_min: if user.user_exists(): - (rc, out, err) = user.set_password_expire_min() + user.set_password_expire_min() module.exit_json(**result) diff --git a/lib/ansible/plugins/connection/__init__.py b/lib/ansible/plugins/connection/__init__.py index 65260ab5bd..5eb3431045 100644 --- a/lib/ansible/plugins/connection/__init__.py +++ b/lib/ansible/plugins/connection/__init__.py @@ -9,7 +9,7 @@ import fcntl import os import shlex -from abc import abstractmethod, abstractproperty +from abc import abstractmethod from functools import wraps from ansible import constants as C @@ -121,7 +121,8 @@ class ConnectionBase(AnsiblePlugin): # In Python3, shlex.split doesn't work on a byte string. return [to_text(x.strip()) for x in shlex.split(argstring) if x.strip()] - @abstractproperty + @property + @abstractmethod def transport(self): """String used to identify this Connection class from other classes""" pass diff --git a/lib/ansible/plugins/lookup/subelements.py b/lib/ansible/plugins/lookup/subelements.py index 27350b08e9..9dc1defb6e 100644 --- a/lib/ansible/plugins/lookup/subelements.py +++ b/lib/ansible/plugins/lookup/subelements.py @@ -126,7 +126,7 @@ class LookupModule(LookupBase): flags = {} if len(terms) == 3: flags = terms[2] - if not isinstance(flags, dict) and not all([isinstance(key, string_types) and key in FLAGS for key in flags]): + if not isinstance(flags, dict) and not all(isinstance(key, string_types) and key in FLAGS for key in flags): _raise_terms_error("the optional third item must be a dict with flags %s" % FLAGS) # build_items diff --git a/lib/ansible/utils/unicode.py b/lib/ansible/utils/unicode.py index 29a52237a6..1218a6e706 100644 --- a/lib/ansible/utils/unicode.py +++ b/lib/ansible/utils/unicode.py @@ -22,7 +22,7 @@ __metaclass__ = type from ansible.module_utils._text import to_text -__all__ = ('unicode_wrap') +__all__ = ('unicode_wrap',) def unicode_wrap(func, *args, **kwargs): diff --git a/test/units/module_utils/basic/test_imports.py b/test/units/module_utils/basic/test_imports.py index eb741de5bb..d1a5f3791e 100644 --- a/test/units/module_utils/basic/test_imports.py +++ b/test/units/module_utils/basic/test_imports.py @@ -43,10 +43,10 @@ class TestImports(ModuleTestCase): @patch.object(builtins, '__import__') def test_module_utils_basic_import_selinux(self, mock_import): - def _mock_import(name, *args, **kwargs): - if name == 'ansible.module_utils.compat.selinux': + def _mock_import(name, globals=None, locals=None, fromlist=tuple(), level=0, **kwargs): + if name == 'ansible.module_utils.compat' and fromlist == ('selinux',): raise ImportError - return realimport(name, *args, **kwargs) + return realimport(name, globals=globals, locals=locals, fromlist=fromlist, level=level, **kwargs) try: self.clear_modules(['ansible.module_utils.compat.selinux', 'ansible.module_utils.basic']) |