Enable pylint rules and fix exposed bugs. (#47219)

* Resolve invalid-unary-operand-type.

* Resolve raising-format-tuple.

* Resolve stop-iteration-return.

* Use disable comment instead of fixing logic.

The affected line in _find_address_range will only fail on Python 3.7
and later if the function is called with an empty address list. As an
internal method it is never called in this way, making it a non-issue
for use via public methods.

Using a comment to disable the rule in favor of an ignore.txt entry
since there are no plans to change the logic in the code itself. This
will also prevent any potential future issues being added in other
parts of the code when updating it based on upstream changes.
pull/47359/head
Matt Clay 6 years ago committed by GitHub
parent cd7232eeb7
commit c24c19594e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -346,7 +346,7 @@ def _find_address_range(addresses):
""" """
it = iter(addresses) it = iter(addresses)
first = last = next(it) first = last = next(it) # pylint: disable=stop-iteration-return
for ip in it: for ip in it:
if ip._ip != last._ip + 1: if ip._ip != last._ip + 1:
yield first, last yield first, last

@ -81,7 +81,7 @@ except ImportError:
if node.name in _safe_names: if node.name in _safe_names:
return _safe_names[node.name] return _safe_names[node.name]
elif isinstance(node, ast.UnarySub): elif isinstance(node, ast.UnarySub):
return -_convert(node.expr) return -_convert(node.expr) # pylint: disable=invalid-unary-operand-type
raise ValueError('malformed string') raise ValueError('malformed string')
return _convert(node_or_string) return _convert(node_or_string)

@ -233,7 +233,7 @@ def set_value(module):
value = module.params.get('value') value = module.params.get('value')
if value is NOT_SET: if value is NOT_SET:
raise AssertionError('Cannot set value of "%s" to `NOT_SET`', (key, )) raise AssertionError('Cannot set value of "%s" to `NOT_SET`' % key)
index, changed = _has_value_changed(consul_api, key, value) index, changed = _has_value_changed(consul_api, key, value)

@ -213,7 +213,7 @@ def doConfigBackUp(module, prompt, answer):
elif(protocol == "tftp"): elif(protocol == "tftp"):
command = "copy " + configType + " " + protocol + " " + protocol command = "copy " + configType + " " + protocol + " " + protocol
command = command + "://" + server + "/" + confPath command = command + "://" + server + "/" + confPath
command = command + + " vrf management\n" command = command + " vrf management\n"
# cnos.debugOutput(command) # cnos.debugOutput(command)
tftp_cmd = [{'command': command, 'prompt': None, 'answer': None}] tftp_cmd = [{'command': command, 'prompt': None, 'answer': None}]
cmd.extend(tftp_cmd) cmd.extend(tftp_cmd)

@ -175,7 +175,7 @@ def doImageDownload(module, prompt, answer):
elif(protocol == "tftp"): elif(protocol == "tftp"):
command = "copy " + protocol + " " + protocol + "://" + server command = "copy " + protocol + " " + protocol + "://" + server
command = command + "/" + imgPath + " system-image " + imgType command = command + "/" + imgPath + " system-image " + imgType
command = command + + " vrf management" command = command + " vrf management"
prompt = ['Confirm download operation', prompt = ['Confirm download operation',
'Do you want to change that to the standby image'] 'Do you want to change that to the standby image']
answer = ['y', 'y'] answer = ['y', 'y']

@ -184,7 +184,6 @@ class SourcesList(object):
for n, valid, enabled, source, comment in sources: for n, valid, enabled, source, comment in sources:
if valid: if valid:
yield file, n, enabled, source, comment yield file, n, enabled, source, comment
raise StopIteration
def _expand_path(self, filename): def _expand_path(self, filename):
if '/' in filename: if '/' in filename:

@ -145,7 +145,10 @@ class GroupBy(object):
def _grouper(self, tgtkey): def _grouper(self, tgtkey):
while self.currkey == tgtkey: while self.currkey == tgtkey:
yield self.currvalue yield self.currvalue
self.currvalue = next(self.it) # Exit on StopIteration try:
self.currvalue = next(self.it) # Exit on StopIteration
except StopIteration:
return
self.currkey = self.keyfunc(self.currvalue) self.currkey = self.keyfunc(self.currvalue)

@ -42,7 +42,6 @@ disable=
invalid-envvar-default, invalid-envvar-default,
invalid-name, invalid-name,
invalid-sequence-index, invalid-sequence-index,
invalid-unary-operand-type,
keyword-arg-before-vararg, keyword-arg-before-vararg,
len-as-condition, len-as-condition,
line-too-long, line-too-long,
@ -66,7 +65,6 @@ disable=
pointless-string-statement, pointless-string-statement,
possibly-unused-variable, possibly-unused-variable,
protected-access, protected-access,
raising-format-tuple,
redefined-argument-from-local, redefined-argument-from-local,
redefined-builtin, redefined-builtin,
redefined-outer-name, redefined-outer-name,
@ -75,7 +73,6 @@ disable=
relative-import, relative-import,
signature-differs, signature-differs,
simplifiable-if-statement, simplifiable-if-statement,
stop-iteration-return,
subprocess-popen-preexec-fn, subprocess-popen-preexec-fn,
super-init-not-called, super-init-not-called,
superfluous-parens, superfluous-parens,

Loading…
Cancel
Save