The following issues were found
Lib/email/_encoded_words.py
7 issues
Line: 67
Column: 1
_q_byte_subber = functools.partial(re.compile(br'=([a-fA-F0-9]{2})').sub,
lambda m: bytes.fromhex(m.group(1).decode()))
def decode_q(encoded):
encoded = encoded.replace(b'_', b' ')
return _q_byte_subber(encoded), []
# dict mapping bytes to their encoded form
Reported by Pylint.
Line: 89
Column: 1
# In headers spaces are mapped to '_'.
_q_byte_map[ord(' ')] = '_'
def encode_q(bstring):
return ''.join(_q_byte_map[x] for x in bstring)
def len_q(bstring):
return sum(len(_q_byte_map[x]) for x in bstring)
Reported by Pylint.
Line: 92
Column: 1
def encode_q(bstring):
return ''.join(_q_byte_map[x] for x in bstring)
def len_q(bstring):
return sum(len(_q_byte_map[x]) for x in bstring)
#
# Base64
Reported by Pylint.
Line: 100
Column: 1
# Base64
#
def decode_b(encoded):
# First try encoding with validate=True, fixing the padding if needed.
# This will succeed only if encoded includes no invalid characters.
pad_err = len(encoded) % 4
missing_padding = b'==='[:4-pad_err] if pad_err else b''
try:
Reported by Pylint.
Line: 138
Column: 1
# way to decode.
return encoded, [errors.InvalidBase64LengthDefect()]
def encode_b(bstring):
return base64.b64encode(bstring).decode('ascii')
def len_b(bstring):
groups_of_3, leftover = divmod(len(bstring), 3)
# 4 bytes out for each 3 bytes (or nonzero fraction thereof) in.
Reported by Pylint.
Line: 141
Column: 1
def encode_b(bstring):
return base64.b64encode(bstring).decode('ascii')
def len_b(bstring):
groups_of_3, leftover = divmod(len(bstring), 3)
# 4 bytes out for each 3 bytes (or nonzero fraction thereof) in.
return groups_of_3 * 4 + (4 if leftover else 0)
Reported by Pylint.
Line: 152
Column: 1
'b': decode_b,
}
def decode(ew):
"""Decode encoded word and return (string, charset, lang, defects) tuple.
An RFC 2047/2243 encoded word has the form:
=?charset*lang?cte?encoded_string?=
Reported by Pylint.
Lib/distutils/tests/test_bdist_msi.py
7 issues
Line: 16
Column: 1
def test_minimal(self):
# minimal test XXX need more tests
from distutils.command.bdist_msi import bdist_msi
project_dir, dist = self.create_dist()
with check_warnings(("", DeprecationWarning)):
cmd = bdist_msi(dist)
cmd.ensure_finalized()
Reported by Pylint.
Line: 16
Column: 9
def test_minimal(self):
# minimal test XXX need more tests
from distutils.command.bdist_msi import bdist_msi
project_dir, dist = self.create_dist()
with check_warnings(("", DeprecationWarning)):
cmd = bdist_msi(dist)
cmd.ensure_finalized()
Reported by Pylint.
Line: 17
Column: 9
def test_minimal(self):
# minimal test XXX need more tests
from distutils.command.bdist_msi import bdist_msi
project_dir, dist = self.create_dist()
with check_warnings(("", DeprecationWarning)):
cmd = bdist_msi(dist)
cmd.ensure_finalized()
Reported by Pylint.
Line: 10
Column: 1
@unittest.skipUnless(sys.platform == 'win32', 'these tests require Windows')
class BDistMSITestCase(support.TempdirManager,
support.LoggingSilencer,
unittest.TestCase):
def test_minimal(self):
# minimal test XXX need more tests
Reported by Pylint.
Line: 14
Column: 5
support.LoggingSilencer,
unittest.TestCase):
def test_minimal(self):
# minimal test XXX need more tests
from distutils.command.bdist_msi import bdist_msi
project_dir, dist = self.create_dist()
with check_warnings(("", DeprecationWarning)):
cmd = bdist_msi(dist)
Reported by Pylint.
Line: 16
Column: 9
def test_minimal(self):
# minimal test XXX need more tests
from distutils.command.bdist_msi import bdist_msi
project_dir, dist = self.create_dist()
with check_warnings(("", DeprecationWarning)):
cmd = bdist_msi(dist)
cmd.ensure_finalized()
Reported by Pylint.
Line: 23
Column: 1
cmd.ensure_finalized()
def test_suite():
return unittest.makeSuite(BDistMSITestCase)
if __name__ == '__main__':
run_unittest(test_suite())
Reported by Pylint.
Lib/codeop.py
7 issues
Line: 96
Column: 13
err1 = e
try:
code2 = compiler(source + "\n\n", filename, symbol)
except SyntaxError as e:
err2 = e
try:
if not code1 and _is_syntax_error(err1, err2):
Reported by Pylint.
Line: 67
Column: 1
__all__ = ["compile_command", "Compile", "CommandCompiler"]
PyCF_DONT_IMPLY_DEDENT = 0x200 # Matches pythonrun.h.
def _maybe_compile(compiler, source, filename, symbol):
# Check for source consisting of only blank lines and comments.
for line in source.split("\n"):
line = line.strip()
Reported by Pylint.
Line: 92
Column: 9
code1 = err1 = err2 = None
try:
code1 = compiler(source + "\n", filename, symbol)
except SyntaxError as e:
err1 = e
try:
code2 = compiler(source + "\n\n", filename, symbol)
except SyntaxError as e:
Reported by Pylint.
Line: 97
Column: 9
try:
code2 = compiler(source + "\n\n", filename, symbol)
except SyntaxError as e:
err2 = e
try:
if not code1 and _is_syntax_error(err1, err2):
raise err1
Reported by Pylint.
Line: 101
Column: 9
err2 = e
try:
if not code1 and _is_syntax_error(err1, err2):
raise err1
else:
return None
finally:
err1 = err2 = None
Reported by Pylint.
Line: 141
Column: 1
"""
return _maybe_compile(_compile, source, filename, symbol)
class Compile:
"""Instances of this class behave much like the built-in compile
function, but if one is used to compile text containing a future
statement, it "remembers" and compiles all subsequent program texts
with the statement in force."""
def __init__(self):
Reported by Pylint.
Line: 156
Column: 1
self.flags |= feature.compiler_flag
return codeob
class CommandCompiler:
"""Instances of this class have __call__ methods identical in
signature to compile_command; the difference is that if the
instance compiles program text containing a __future__ statement,
the instance 'remembers' and compiles all subsequent program texts
with the statement in force."""
Reported by Pylint.
Lib/lib2to3/fixes/fix_standarderror.py
7 issues
Line: 7
Column: 1
"""Fixer for StandardError -> Exception."""
# Local imports
from .. import fixer_base
from ..fixer_util import Name
class FixStandarderror(fixer_base.BaseFix):
BM_compatible = True
Reported by Pylint.
Line: 8
Column: 1
# Local imports
from .. import fixer_base
from ..fixer_util import Name
class FixStandarderror(fixer_base.BaseFix):
BM_compatible = True
PATTERN = """
Reported by Pylint.
Line: 17
Column: 31
'StandardError'
"""
def transform(self, node, results):
return Name("Exception", prefix=node.prefix)
Reported by Pylint.
Line: 11
Column: 1
from ..fixer_util import Name
class FixStandarderror(fixer_base.BaseFix):
BM_compatible = True
PATTERN = """
'StandardError'
"""
Reported by Pylint.
Line: 11
Column: 1
from ..fixer_util import Name
class FixStandarderror(fixer_base.BaseFix):
BM_compatible = True
PATTERN = """
'StandardError'
"""
Reported by Pylint.
Line: 17
Column: 5
'StandardError'
"""
def transform(self, node, results):
return Name("Exception", prefix=node.prefix)
Reported by Pylint.
Line: 17
Column: 5
'StandardError'
"""
def transform(self, node, results):
return Name("Exception", prefix=node.prefix)
Reported by Pylint.
Lib/lib2to3/fixes/fix_getcwdu.py
7 issues
Line: 7
Column: 1
# Author: Victor Stinner
# Local imports
from .. import fixer_base
from ..fixer_util import Name
class FixGetcwdu(fixer_base.BaseFix):
BM_compatible = True
Reported by Pylint.
Line: 8
Column: 1
# Local imports
from .. import fixer_base
from ..fixer_util import Name
class FixGetcwdu(fixer_base.BaseFix):
BM_compatible = True
PATTERN = """
Reported by Pylint.
Line: 17
Column: 25
power< 'os' trailer< dot='.' name='getcwdu' > any* >
"""
def transform(self, node, results):
name = results["name"]
name.replace(Name("getcwd", prefix=name.prefix))
Reported by Pylint.
Line: 10
Column: 1
from .. import fixer_base
from ..fixer_util import Name
class FixGetcwdu(fixer_base.BaseFix):
BM_compatible = True
PATTERN = """
power< 'os' trailer< dot='.' name='getcwdu' > any* >
"""
Reported by Pylint.
Line: 10
Column: 1
from .. import fixer_base
from ..fixer_util import Name
class FixGetcwdu(fixer_base.BaseFix):
BM_compatible = True
PATTERN = """
power< 'os' trailer< dot='.' name='getcwdu' > any* >
"""
Reported by Pylint.
Line: 17
Column: 5
power< 'os' trailer< dot='.' name='getcwdu' > any* >
"""
def transform(self, node, results):
name = results["name"]
name.replace(Name("getcwd", prefix=name.prefix))
Reported by Pylint.
Line: 17
Column: 5
power< 'os' trailer< dot='.' name='getcwdu' > any* >
"""
def transform(self, node, results):
name = results["name"]
name.replace(Name("getcwd", prefix=name.prefix))
Reported by Pylint.
Lib/lib2to3/fixes/fix_ws_comma.py
7 issues
Line: 8
Column: 1
"""
from .. import pytree
from ..pgen2 import token
from .. import fixer_base
class FixWsComma(fixer_base.BaseFix):
Reported by Pylint.
Line: 9
Column: 1
"""
from .. import pytree
from ..pgen2 import token
from .. import fixer_base
class FixWsComma(fixer_base.BaseFix):
explicit = True # The user must ask for this fixers
Reported by Pylint.
Line: 10
Column: 1
from .. import pytree
from ..pgen2 import token
from .. import fixer_base
class FixWsComma(fixer_base.BaseFix):
explicit = True # The user must ask for this fixers
Reported by Pylint.
Line: 24
Column: 31
COLON = pytree.Leaf(token.COLON, ":")
SEPS = (COMMA, COLON)
def transform(self, node, results):
new = node.clone()
comma = False
for child in new.children:
if child in self.SEPS:
prefix = child.prefix
Reported by Pylint.
Line: 12
Column: 1
from ..pgen2 import token
from .. import fixer_base
class FixWsComma(fixer_base.BaseFix):
explicit = True # The user must ask for this fixers
PATTERN = """
any<(not(',') any)+ ',' ((not(',') any)+ ',')* [not(',') any]>
Reported by Pylint.
Line: 12
Column: 1
from ..pgen2 import token
from .. import fixer_base
class FixWsComma(fixer_base.BaseFix):
explicit = True # The user must ask for this fixers
PATTERN = """
any<(not(',') any)+ ',' ((not(',') any)+ ',')* [not(',') any]>
Reported by Pylint.
Line: 24
Column: 5
COLON = pytree.Leaf(token.COLON, ":")
SEPS = (COMMA, COLON)
def transform(self, node, results):
new = node.clone()
comma = False
for child in new.children:
if child in self.SEPS:
prefix = child.prefix
Reported by Pylint.
Lib/html/__init__.py
7 issues
Line: 114
Column: 9
for x in range(len(s)-1, 1, -1):
if s[:x] in _html5:
return _html5[s[:x]] + s[x:]
else:
return '&' + s
_charref = _re.compile(r'&(#[0-9]+;?'
r'|#[xX][0-9a-fA-F]+;?'
Reported by Pylint.
Line: 12
Column: 1
__all__ = ['escape', 'unescape']
def escape(s, quote=True):
"""
Replace special characters "&", "<" and ">" to HTML-safe sequences.
If the optional flag quote is true (the default), the quotation mark
characters, both double quote (") and single quote (') characters are also
translated.
Reported by Pylint.
Line: 91
Column: 1
}
def _replace_charref(s):
s = s.group(1)
if s[0] == '#':
# numeric charref
if s[1] in 'xX':
num = int(s[2:].rstrip(';'), 16)
Reported by Pylint.
Line: 91
Column: 1
}
def _replace_charref(s):
s = s.group(1)
if s[0] == '#':
# numeric charref
if s[1] in 'xX':
num = int(s[2:].rstrip(';'), 16)
Reported by Pylint.
Line: 93
Column: 5
def _replace_charref(s):
s = s.group(1)
if s[0] == '#':
# numeric charref
if s[1] in 'xX':
num = int(s[2:].rstrip(';'), 16)
else:
num = int(s[1:].rstrip(';'))
Reported by Pylint.
Line: 111
Column: 13
if s in _html5:
return _html5[s]
# find the longest matching name (as defined by the standard)
for x in range(len(s)-1, 1, -1):
if s[:x] in _html5:
return _html5[s[:x]] + s[x:]
else:
return '&' + s
Reported by Pylint.
Line: 122
Column: 1
r'|#[xX][0-9a-fA-F]+;?'
r'|[^\t\n\f <&#;]{1,32};?)')
def unescape(s):
"""
Convert all named and numeric character references (e.g. >, >,
&x3e;) in the string s to the corresponding unicode characters.
This function uses the rules defined by the HTML 5 standard
for both valid and invalid character references, and the list of
Reported by Pylint.
Lib/graphlib.py
7 issues
Line: 36
Column: 5
the same, to make it clear that it is cyclic.
"""
pass
class TopologicalSorter:
"""Provides functionality to topologically sort a graph of hashable nodes"""
Reported by Pylint.
Line: 104
Column: 30
# nodes as possible before cycles block more progress
cycle = self._find_cycle()
if cycle:
raise CycleError(f"nodes are in a cycle", cycle)
def get_ready(self):
"""Return a tuple of all the nodes that are ready.
Initially it returns all nodes with no predecessors; once those are marked
Reported by Pylint.
Line: 1
Column: 1
__all__ = ["TopologicalSorter", "CycleError"]
_NODE_OUT = -1
_NODE_DONE = -2
class _NodeInfo:
__slots__ = "node", "npredecessors", "successors"
Reported by Pylint.
Line: 7
Column: 1
_NODE_DONE = -2
class _NodeInfo:
__slots__ = "node", "npredecessors", "successors"
def __init__(self, node):
# The node this class is augmenting.
self.node = node
Reported by Pylint.
Line: 175
Column: 17
# If the node has not being returned (marked as ready) previously, inform the user.
stat = nodeinfo.npredecessors
if stat != _NODE_OUT:
if stat >= 0:
raise ValueError(
f"node {node!r} was not passed out (still not ready)"
)
elif stat == _NODE_DONE:
raise ValueError(f"node {node!r} was already marked done")
Reported by Pylint.
Line: 182
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
elif stat == _NODE_DONE:
raise ValueError(f"node {node!r} was already marked done")
else:
assert False, f"node {node!r}: unknown status {stat}"
# Mark the node as processed
nodeinfo.npredecessors = _NODE_DONE
# Go to all the successors and reduce the number of predecessors, collecting all the ones
Reported by Bandit.
Line: 187
Column: 1
# Mark the node as processed
nodeinfo.npredecessors = _NODE_DONE
# Go to all the successors and reduce the number of predecessors, collecting all the ones
# that are ready to be returned in the next get_ready() call.
for successor in nodeinfo.successors:
successor_info = n2i[successor]
successor_info.npredecessors -= 1
if successor_info.npredecessors == 0:
Reported by Pylint.
Lib/distutils/command/install_data.py
7 issues
Line: 56
Column: 17
self.outfiles.append(out)
else:
# it's a tuple with path to install to and a list of files
dir = convert_path(f[0])
if not os.path.isabs(dir):
dir = os.path.join(self.install_dir, dir)
elif self.root:
dir = change_root(self.root, dir)
self.mkpath(dir)
Reported by Pylint.
Line: 12
Column: 1
from distutils.core import Command
from distutils.util import change_root, convert_path
class install_data(Command):
description = "install data files"
user_options = [
('install-dir=', 'd',
Reported by Pylint.
Line: 12
Column: 1
from distutils.core import Command
from distutils.util import change_root, convert_path
class install_data(Command):
description = "install data files"
user_options = [
('install-dir=', 'd',
Reported by Pylint.
Line: 44
Column: 13
def run(self):
self.mkpath(self.install_dir)
for f in self.data_files:
if isinstance(f, str):
# it's a simple file, so copy it
f = convert_path(f)
if self.warn_dir:
self.warn("setup script did not provide a directory for "
Reported by Pylint.
Line: 47
Column: 17
for f in self.data_files:
if isinstance(f, str):
# it's a simple file, so copy it
f = convert_path(f)
if self.warn_dir:
self.warn("setup script did not provide a directory for "
"'%s' -- installing right in '%s'" %
(f, self.install_dir))
(out, _) = self.copy_file(f, self.install_dir)
Reported by Pylint.
Line: 75
Column: 5
(out, _) = self.copy_file(data, dir)
self.outfiles.append(out)
def get_inputs(self):
return self.data_files or []
def get_outputs(self):
return self.outfiles
Reported by Pylint.
Line: 78
Column: 5
def get_inputs(self):
return self.data_files or []
def get_outputs(self):
return self.outfiles
Reported by Pylint.
Lib/lib2to3/fixes/fix_future.py
7 issues
Line: 8
Column: 1
# Author: Christian Heimes
# Local imports
from .. import fixer_base
from ..fixer_util import BlankLine
class FixFuture(fixer_base.BaseFix):
BM_compatible = True
Reported by Pylint.
Line: 9
Column: 1
# Local imports
from .. import fixer_base
from ..fixer_util import BlankLine
class FixFuture(fixer_base.BaseFix):
BM_compatible = True
PATTERN = """import_from< 'from' module_name="__future__" 'import' any >"""
Reported by Pylint.
Line: 19
Column: 31
# This should be run last -- some things check for the import
run_order = 10
def transform(self, node, results):
new = BlankLine()
new.prefix = node.prefix
return new
Reported by Pylint.
Line: 11
Column: 1
from .. import fixer_base
from ..fixer_util import BlankLine
class FixFuture(fixer_base.BaseFix):
BM_compatible = True
PATTERN = """import_from< 'from' module_name="__future__" 'import' any >"""
# This should be run last -- some things check for the import
Reported by Pylint.
Line: 11
Column: 1
from .. import fixer_base
from ..fixer_util import BlankLine
class FixFuture(fixer_base.BaseFix):
BM_compatible = True
PATTERN = """import_from< 'from' module_name="__future__" 'import' any >"""
# This should be run last -- some things check for the import
Reported by Pylint.
Line: 19
Column: 5
# This should be run last -- some things check for the import
run_order = 10
def transform(self, node, results):
new = BlankLine()
new.prefix = node.prefix
return new
Reported by Pylint.
Line: 19
Column: 5
# This should be run last -- some things check for the import
run_order = 10
def transform(self, node, results):
new = BlankLine()
new.prefix = node.prefix
return new
Reported by Pylint.