mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Pylint fixes
This commit is contained in:
parent
1a1ce05186
commit
35b2076584
22 changed files with 35 additions and 42 deletions
|
@ -60,7 +60,7 @@ def __define_global_system_encoding_variable__():
|
|||
# than expected. See:
|
||||
# https://github.com/saltstack/salt/issues/21036
|
||||
if sys.version_info[0] < 3:
|
||||
import __builtin__ as builtins # pylint: disable=incompatible-py3-code
|
||||
import __builtin__ as builtins
|
||||
else:
|
||||
import builtins # pylint: disable=import-error
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ if PY3:
|
|||
import builtins
|
||||
exceptions = builtins
|
||||
else:
|
||||
import exceptions # pylint: disable=incompatible-py3-code
|
||||
import exceptions
|
||||
|
||||
|
||||
if not hasattr(ElementTree, 'ParseError'):
|
||||
|
|
|
@ -15,7 +15,6 @@ import struct
|
|||
|
||||
# Import Salt Libs
|
||||
import salt.utils
|
||||
from salt.ext.six.moves import range # pylint: disable=import-error,redefined-builtin
|
||||
|
||||
__virtualname__ = 'btmp'
|
||||
BTMP = '/var/log/btmp'
|
||||
|
|
|
@ -10,7 +10,6 @@ import time
|
|||
# Import salt libs
|
||||
import salt.utils
|
||||
import salt.utils.vt
|
||||
from salt.ext.six.moves import range # pylint: disable=import-error,redefined-builtin
|
||||
|
||||
__virtualname__ = 'sh'
|
||||
|
||||
|
|
|
@ -13,9 +13,6 @@ from __future__ import absolute_import
|
|||
import os
|
||||
import struct
|
||||
|
||||
# Import 3rd-party libs
|
||||
from salt.ext.six.moves import range
|
||||
|
||||
# Import salt libs
|
||||
import salt.utils
|
||||
|
||||
|
|
|
@ -1199,7 +1199,7 @@ def session_create(consul_url=None, **kwargs):
|
|||
if str(_ttl).endswith('s'):
|
||||
_ttl = _ttl[:-1]
|
||||
|
||||
if not int(_ttl) >= 0 and not int(_ttl) <= 3600:
|
||||
if int(_ttl) < 0 or int(_ttl) > 3600:
|
||||
ret['message'] = ('TTL must be ',
|
||||
'between 0 and 3600.')
|
||||
ret['res'] = False
|
||||
|
|
|
@ -342,7 +342,7 @@ def __is_long(token):
|
|||
|
||||
def __get_long(token):
|
||||
if six.PY2:
|
||||
return long(token[0:-1]) # pylint: disable=incompatible-py3-code
|
||||
return long(token[0:-1])
|
||||
else:
|
||||
return int(token[0:-1])
|
||||
|
||||
|
|
|
@ -79,9 +79,9 @@ def doc(*args):
|
|||
else:
|
||||
target_mod = ''
|
||||
if _use_fnmatch:
|
||||
for fun in fnmatch.filter(__salt__.keys(), target_mod): # pylint: disable=incompatible-py3-code
|
||||
docs[fun] = __salt__[fun].__doc__ # There's no problem feeding fnmatch.filter()
|
||||
else: # with a Py3's dict_keys() instance
|
||||
for fun in fnmatch.filter(__salt__.keys(), target_mod):
|
||||
docs[fun] = __salt__[fun].__doc__
|
||||
else:
|
||||
|
||||
for fun in __salt__:
|
||||
if fun == module or fun.startswith(target_mod):
|
||||
|
@ -313,9 +313,8 @@ def renderer_doc(*args):
|
|||
|
||||
for module in args:
|
||||
if '*' in module:
|
||||
for fun in fnmatch.filter(renderers_.keys(), module): # pylint: disable=incompatible-py3-code
|
||||
docs[fun] = renderers_[fun].__doc__ # There's no problem feeding fnmatch.filter()
|
||||
# with a Py3's dict_keys() instance
|
||||
for fun in fnmatch.filter(renderers_.keys(), module):
|
||||
docs[fun] = renderers_[fun].__doc__
|
||||
else:
|
||||
for fun in six.iterkeys(renderers_):
|
||||
docs[fun] = renderers_[fun].__doc__
|
||||
|
@ -745,9 +744,9 @@ def list_returners(*args):
|
|||
return sorted(returners)
|
||||
|
||||
for module in args:
|
||||
for func in fnmatch.filter(returners_.keys(), module): # pylint: disable=incompatible-py3-code
|
||||
comps = func.split('.') # There's no problem feeding fnmatch.filter()
|
||||
if len(comps) < 2: # with a Py3's dict_keys() instance
|
||||
for func in fnmatch.filter(returners_.keys(), module):
|
||||
comps = func.split('.')
|
||||
if len(comps) < 2:
|
||||
continue
|
||||
returners.add(comps[0])
|
||||
return sorted(returners)
|
||||
|
|
|
@ -180,8 +180,9 @@ def create_event(message_type=None, routing_key='everybody', **kwargs):
|
|||
timestamp = datetime.datetime.strptime(kwargs['timestamp'], timestamp_fmt)
|
||||
data['timestamp'] = int(time.mktime(timestamp.timetuple()))
|
||||
except (TypeError, ValueError):
|
||||
raise SaltInvocationError('Date string could not be parsed: %s, %s',
|
||||
kwargs['timestamp'], timestamp_fmt)
|
||||
raise SaltInvocationError('Date string could not be parsed: {0}, {1}'.format(
|
||||
kwargs['timestamp'], timestamp_fmt)
|
||||
)
|
||||
|
||||
if 'state_start_time' in kwargs:
|
||||
state_start_time_fmt = kwargs.get('state_start_time_fmt', '%Y-%m-%dT%H:%M:%S')
|
||||
|
@ -190,8 +191,9 @@ def create_event(message_type=None, routing_key='everybody', **kwargs):
|
|||
state_start_time = datetime.datetime.strptime(kwargs['state_start_time'], state_start_time_fmt)
|
||||
data['state_start_time'] = int(time.mktime(state_start_time.timetuple()))
|
||||
except (TypeError, ValueError):
|
||||
raise SaltInvocationError('Date string could not be parsed: %s, %s',
|
||||
kwargs['state_start_time'], state_start_time_fmt)
|
||||
raise SaltInvocationError('Date string could not be parsed: {0}, {1}'.format(
|
||||
kwargs['state_start_time'], state_start_time_fmt)
|
||||
)
|
||||
|
||||
for kwarg in keyword_args:
|
||||
if kwarg in kwargs:
|
||||
|
|
|
@ -864,7 +864,7 @@ def remove(name=None, pkgs=None, version=None, **kwargs):
|
|||
else:
|
||||
if not version_num == old.get(target) \
|
||||
and not old.get(target) == "Not Found" \
|
||||
and not version_num == 'latest':
|
||||
and version_num != 'latest':
|
||||
log.error('{0} {1} not installed'.format(target, version))
|
||||
ret[target] = {'current': '{0} not installed'.format(version_num)}
|
||||
continue
|
||||
|
|
|
@ -77,7 +77,7 @@ def _is_zypper_error(retcode):
|
|||
Otherwise False
|
||||
'''
|
||||
# see man zypper for existing exit codes
|
||||
return not int(retcode) in [0, 100, 101, 102, 103]
|
||||
return int(retcode) not in [0, 100, 101, 102, 103]
|
||||
|
||||
|
||||
def _zypper_check_result(result, xml=False):
|
||||
|
@ -326,7 +326,7 @@ def upgrade_available(name):
|
|||
|
||||
salt '*' pkg.upgrade_available <package name>
|
||||
'''
|
||||
return not not latest_version(name)
|
||||
return latest_version(name)
|
||||
|
||||
|
||||
def version(*names, **kwargs):
|
||||
|
|
|
@ -152,7 +152,7 @@ class Serial(object):
|
|||
for idx, entry in enumerate(obj):
|
||||
obj[idx] = verylong_encoder(entry)
|
||||
return obj
|
||||
if six.PY2 and isinstance(obj, long) and long > pow(2, 64): # pylint: disable=incompatible-py3-code
|
||||
if six.PY2 and isinstance(obj, long) and long > pow(2, 64):
|
||||
return str(obj)
|
||||
elif six.PY3 and isinstance(obj, int) and int > pow(2, 64):
|
||||
return str(obj)
|
||||
|
|
|
@ -72,7 +72,7 @@ def execution():
|
|||
for v in six.itervalues(ret):
|
||||
docs.update(v)
|
||||
except SaltClientError as exc:
|
||||
print(exc) # pylint: disable=W1698
|
||||
print(exc)
|
||||
return []
|
||||
|
||||
i = itertools.chain.from_iterable([six.iteritems(docs['ret'])])
|
||||
|
|
|
@ -390,7 +390,7 @@ Dumper.add_multi_representer(type(None), Dumper.represent_none)
|
|||
if six.PY2:
|
||||
Dumper.add_multi_representer(six.binary_type, Dumper.represent_str)
|
||||
Dumper.add_multi_representer(six.text_type, Dumper.represent_unicode)
|
||||
Dumper.add_multi_representer(long, Dumper.represent_long) # pylint: disable=incompatible-py3-code
|
||||
Dumper.add_multi_representer(long, Dumper.represent_long)
|
||||
else:
|
||||
Dumper.add_multi_representer(six.binary_type, Dumper.represent_binary)
|
||||
Dumper.add_multi_representer(six.text_type, Dumper.represent_str)
|
||||
|
|
|
@ -2035,7 +2035,7 @@ def alias_function(fun, name, doc=None):
|
|||
if six.PY3:
|
||||
orig_name = fun.__name__
|
||||
else:
|
||||
orig_name = fun.func_name # pylint: disable=incompatible-py3-code
|
||||
orig_name = fun.func_name
|
||||
|
||||
alias_msg = ('\nThis function is an alias of '
|
||||
'``{0}``.\n'.format(orig_name))
|
||||
|
@ -2814,7 +2814,7 @@ def to_str(s, encoding=None):
|
|||
else:
|
||||
if isinstance(s, bytearray):
|
||||
return str(s)
|
||||
if isinstance(s, unicode): # pylint: disable=incompatible-py3-code
|
||||
if isinstance(s, unicode):
|
||||
return s.encode(encoding or __salt_system_encoding__)
|
||||
raise TypeError('expected str, bytearray, or unicode')
|
||||
|
||||
|
@ -2845,7 +2845,7 @@ def to_unicode(s, encoding=None):
|
|||
else:
|
||||
if isinstance(s, str):
|
||||
return s.decode(encoding or __salt_system_encoding__)
|
||||
return unicode(s) # pylint: disable=incompatible-py3-code
|
||||
return unicode(s)
|
||||
|
||||
|
||||
def is_list(value):
|
||||
|
|
|
@ -27,7 +27,7 @@ def condition_input(args, kwargs):
|
|||
# XXX: We might need to revisit this code when we move to Py3
|
||||
# since long's are int's in Py3
|
||||
if (six.PY3 and isinstance(arg, six.integer_types)) or \
|
||||
(six.PY2 and isinstance(arg, long)): # pylint: disable=incompatible-py3-code
|
||||
(six.PY2 and isinstance(arg, long)):
|
||||
ret.append(str(arg))
|
||||
else:
|
||||
ret.append(arg)
|
||||
|
|
|
@ -38,7 +38,7 @@ def deepcopy_bound(name):
|
|||
|
||||
'''
|
||||
def _deepcopy_method(x, memo):
|
||||
return type(x)(x.im_func, copy.deepcopy(x.im_self, memo), x.im_class) # pylint: disable=W1699
|
||||
return type(x)(x.im_func, copy.deepcopy(x.im_self, memo), x.im_class)
|
||||
try:
|
||||
pre_dispatch = copy._deepcopy_dispatch
|
||||
copy._deepcopy_dispatch[types.MethodType] = _deepcopy_method
|
||||
|
|
|
@ -279,7 +279,7 @@ except ImportError:
|
|||
|
||||
'''
|
||||
if isinstance(other, OrderedDict):
|
||||
return len(self) == len(other) and self.items() == other.items() # pylint: disable=incompatible-py3-code
|
||||
return len(self) == len(other) and self.items() == other.items()
|
||||
return dict.__eq__(self, other)
|
||||
|
||||
def __ne__(self, other):
|
||||
|
@ -327,7 +327,7 @@ class DefaultOrderedDict(OrderedDict):
|
|||
args = tuple()
|
||||
else:
|
||||
args = self.default_factory,
|
||||
return type(self), args, None, None, self.items() # pylint: disable=incompatible-py3-code
|
||||
return type(self), args, None, None, self.items()
|
||||
|
||||
def copy(self):
|
||||
return self.__copy__()
|
||||
|
@ -338,7 +338,7 @@ class DefaultOrderedDict(OrderedDict):
|
|||
def __deepcopy__(self):
|
||||
import copy
|
||||
return type(self)(self.default_factory,
|
||||
copy.deepcopy(self.items())) # pylint: disable=incompatible-py3-code
|
||||
copy.deepcopy(self.items()))
|
||||
|
||||
def __repr__(self, _repr_running={}): # pylint: disable=W0102
|
||||
return 'DefaultOrderedDict({0}, {1})'.format(self.default_factory,
|
||||
|
|
|
@ -3,8 +3,6 @@
|
|||
Set up the version of Salt
|
||||
'''
|
||||
|
||||
# pylint: disable=incompatible-py3-code
|
||||
|
||||
# Import python libs
|
||||
from __future__ import absolute_import, print_function
|
||||
import re
|
||||
|
|
|
@ -44,6 +44,7 @@ def not_loaded():
|
|||
return True
|
||||
'''
|
||||
|
||||
|
||||
class LazyLoaderTest(TestCase):
|
||||
'''
|
||||
Test the loader
|
||||
|
|
|
@ -39,9 +39,7 @@ class CopyTest(integration.ShellCase, integration.ShellCaseCommonTestsMixIn):
|
|||
if not line:
|
||||
continue
|
||||
data = yaml.load(line)
|
||||
minions.extend(data.keys()) # pylint: disable=incompatible-py3-code
|
||||
# since we're extending a list, the Py3 dict_keys view will behave
|
||||
# as expected.
|
||||
minions.extend(data.keys())
|
||||
|
||||
self.assertNotEqual(minions, [])
|
||||
|
||||
|
|
|
@ -124,7 +124,7 @@ class PCAPParser(object):
|
|||
'tcp': {}
|
||||
}
|
||||
|
||||
(header, packet) = cap.next() # pylint: disable=W1699
|
||||
(header, packet) = cap.next()
|
||||
|
||||
eth_length, eth_protocol = self.parse_ether(packet)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue