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.
pull/75479/head
Matt Clay 3 years ago committed by GitHub
parent dc6878007b
commit ce6d8a143c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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.

@ -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

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

@ -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

@ -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

@ -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):

@ -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'])

Loading…
Cancel
Save