The following issues were found

Lib/lib2to3/tests/pytree_idempotency.py
22 issues
Starting a process with a shell, possible injection detected, security issue.
Security injection

Line: 89
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b605_start_process_with_a_shell.html

                  finally:
        f.close()
    try:
        return os.system("diff -u %s @" % fn)
    finally:
        os.remove("@")

if __name__ == "__main__":
    main()

            

Reported by Bandit.

Attempted relative import beyond top-level package
Error

Line: 12 Column: 1

              __author__ = "Guido van Rossum <guido@python.org>"

# Support imports (need to be imported first)
from . import support

# Python imports
import os
import sys
import logging

            

Reported by Pylint.

Attempted relative import beyond top-level package
Error

Line: 20 Column: 1

              import logging

# Local imports
from .. import pytree
from .. import pgen2
from ..pgen2 import driver

logging.basicConfig()


            

Reported by Pylint.

Attempted relative import beyond top-level package
Error

Line: 21 Column: 1

              
# Local imports
from .. import pytree
from .. import pgen2
from ..pgen2 import driver

logging.basicConfig()

def main():

            

Reported by Pylint.

Attempted relative import beyond top-level package
Error

Line: 22 Column: 1

              # Local imports
from .. import pytree
from .. import pgen2
from ..pgen2 import driver

logging.basicConfig()

def main():
    gr = driver.load_grammar("Grammar.txt")

            

Reported by Pylint.

Unused import support
Error

Line: 12 Column: 1

              __author__ = "Guido van Rossum <guido@python.org>"

# Support imports (need to be imported first)
from . import support

# Python imports
import os
import sys
import logging

            

Reported by Pylint.

Redefining built-in 'dir'
Error

Line: 55 Column: 9

                          problems.append(fn)

    # Process every single module on sys.path (but not in packages)
    for dir in sys.path:
        try:
            names = os.listdir(dir)
        except OSError:
            continue
        print("Scanning", dir, "...", file=sys.stderr)

            

Reported by Pylint.

standard import "import os" should be placed before "from . import support"
Error

Line: 15 Column: 1

              from . import support

# Python imports
import os
import sys
import logging

# Local imports
from .. import pytree

            

Reported by Pylint.

standard import "import sys" should be placed before "from . import support"
Error

Line: 16 Column: 1

              
# Python imports
import os
import sys
import logging

# Local imports
from .. import pytree
from .. import pgen2

            

Reported by Pylint.

standard import "import logging" should be placed before "from . import support"
Error

Line: 17 Column: 1

              # Python imports
import os
import sys
import logging

# Local imports
from .. import pytree
from .. import pgen2
from ..pgen2 import driver

            

Reported by Pylint.

Lib/distutils/tests/test_config_cmd.py
22 issues
Unused argument 'args'
Error

Line: 16 Column: 1

                                   support.TempdirManager,
                     unittest.TestCase):

    def _info(self, msg, *args):
        for line in msg.splitlines():
            self._logs.append(line)

    def setUp(self):
        super(ConfigTestCase, self).setUp()

            

Reported by Pylint.

Access to a protected member _CONFIG_VARS of a client class
Error

Line: 25 Column: 37

                      self._logs = []
        self.old_log = log.info
        log.info = self._info
        self.old_config_vars = dict(sysconfig._CONFIG_VARS)

    def tearDown(self):
        log.info = self.old_log
        sysconfig._CONFIG_VARS.clear()
        sysconfig._CONFIG_VARS.update(self.old_config_vars)

            

Reported by Pylint.

Access to a protected member _CONFIG_VARS of a client class
Error

Line: 29 Column: 9

              
    def tearDown(self):
        log.info = self.old_log
        sysconfig._CONFIG_VARS.clear()
        sysconfig._CONFIG_VARS.update(self.old_config_vars)
        super(ConfigTestCase, self).tearDown()

    def test_dump_file(self):
        this_file = os.path.splitext(__file__)[0] + '.py'

            

Reported by Pylint.

Access to a protected member _CONFIG_VARS of a client class
Error

Line: 30 Column: 9

                  def tearDown(self):
        log.info = self.old_log
        sysconfig._CONFIG_VARS.clear()
        sysconfig._CONFIG_VARS.update(self.old_config_vars)
        super(ConfigTestCase, self).tearDown()

    def test_dump_file(self):
        this_file = os.path.splitext(__file__)[0] + '.py'
        f = open(this_file)

            

Reported by Pylint.

Unused variable 'pkg_dir'
Error

Line: 49 Column: 9

                      cmd = missing_compiler_executable(['preprocessor'])
        if cmd is not None:
            self.skipTest('The %r command is not found' % cmd)
        pkg_dir, dist = self.create_dist()
        cmd = config(dist)
        cmd._check_compiler()
        compiler = cmd.compiler
        if sys.platform[:3] == "aix" and "xlc" in compiler.preprocessor[0].lower():
            self.skipTest('xlc: The -E option overrides the -P, -o, and -qsyntaxonly options')

            

Reported by Pylint.

Access to a protected member _check_compiler of a client class
Error

Line: 51 Column: 9

                          self.skipTest('The %r command is not found' % cmd)
        pkg_dir, dist = self.create_dist()
        cmd = config(dist)
        cmd._check_compiler()
        compiler = cmd.compiler
        if sys.platform[:3] == "aix" and "xlc" in compiler.preprocessor[0].lower():
            self.skipTest('xlc: The -E option overrides the -P, -o, and -qsyntaxonly options')

        # simple pattern searches

            

Reported by Pylint.

Unused variable 'pkg_dir'
Error

Line: 66 Column: 9

                  def test_finalize_options(self):
        # finalize_options does a bit of transformation
        # on options
        pkg_dir, dist = self.create_dist()
        cmd = config(dist)
        cmd.include_dirs = 'one%stwo' % os.pathsep
        cmd.libraries = 'one'
        cmd.library_dirs = 'three%sfour' % os.pathsep
        cmd.ensure_finalized()

            

Reported by Pylint.

Unused variable 'pkg_dir'
Error

Line: 89 Column: 9

                      for f in (f1, f2):
            self.assertTrue(os.path.exists(f))

        pkg_dir, dist = self.create_dist()
        cmd = config(dist)
        cmd._clean(f1, f2)

        for f in (f1, f2):
            self.assertFalse(os.path.exists(f))

            

Reported by Pylint.

Access to a protected member _clean of a client class
Error

Line: 91 Column: 9

              
        pkg_dir, dist = self.create_dist()
        cmd = config(dist)
        cmd._clean(f1, f2)

        for f in (f1, f2):
            self.assertFalse(os.path.exists(f))

def test_suite():

            

Reported by Pylint.

Missing class docstring
Error

Line: 12 Column: 1

              from distutils.tests import support
from distutils import log

class ConfigTestCase(support.LoggingSilencer,
                     support.TempdirManager,
                     unittest.TestCase):

    def _info(self, msg, *args):
        for line in msg.splitlines():

            

Reported by Pylint.

Lib/distutils/tests/test_check.py
22 issues
Unused variable 'pkg_info'
Error

Line: 30 Column: 9

                      if cwd is not None:
            old_dir = os.getcwd()
            os.chdir(cwd)
        pkg_info, dist = self.create_dist(**metadata)
        cmd = check(dist)
        cmd.initialize_options()
        for name, value in options.items():
            setattr(cmd, name, value)
        cmd.ensure_finalized()

            

Reported by Pylint.

Access to a protected member _warnings of a client class
Error

Line: 46 Column: 26

                      # by default, check is checking the metadata
        # should have some warnings
        cmd = self._run()
        self.assertEqual(cmd._warnings, 2)

        # now let's add the required fields
        # and run it again, to make sure we don't get
        # any warning anymore
        metadata = {'url': 'xxx', 'author': 'xxx',

            

Reported by Pylint.

Access to a protected member _warnings of a client class
Error

Line: 55 Column: 26

                                  'author_email': 'xxx',
                    'name': 'xxx', 'version': 'xxx'}
        cmd = self._run(metadata)
        self.assertEqual(cmd._warnings, 0)

        # now with the strict mode, we should
        # get an error if there are missing metadata
        self.assertRaises(DistutilsSetupError, self._run, {}, **{'strict': 1})


            

Reported by Pylint.

Access to a protected member _warnings of a client class
Error

Line: 63 Column: 26

              
        # and of course, no error when all metadata are present
        cmd = self._run(metadata, strict=1)
        self.assertEqual(cmd._warnings, 0)

        # now a test with non-ASCII characters
        metadata = {'url': 'xxx', 'author': '\u00c9ric',
                    'author_email': 'xxx', 'name': 'xxx',
                    'version': 'xxx',

            

Reported by Pylint.

Access to a protected member _warnings of a client class
Error

Line: 72 Column: 26

                                  'description': 'Something about esszet \u00df',
                    'long_description': 'More things about esszet \u00df'}
        cmd = self._run(metadata)
        self.assertEqual(cmd._warnings, 0)

    @unittest.skipUnless(HAS_DOCUTILS, "won't test without docutils")
    def test_check_document(self):
        pkg_info, dist = self.create_dist()
        cmd = check(dist)

            

Reported by Pylint.

Unused variable 'pkg_info'
Error

Line: 76 Column: 9

              
    @unittest.skipUnless(HAS_DOCUTILS, "won't test without docutils")
    def test_check_document(self):
        pkg_info, dist = self.create_dist()
        cmd = check(dist)

        # let's see if it detects broken rest
        broken_rest = 'title\n===\n\ntest'
        msgs = cmd._check_rst_data(broken_rest)

            

Reported by Pylint.

Access to a protected member _check_rst_data of a client class
Error

Line: 81 Column: 16

              
        # let's see if it detects broken rest
        broken_rest = 'title\n===\n\ntest'
        msgs = cmd._check_rst_data(broken_rest)
        self.assertEqual(len(msgs), 1)

        # and non-broken rest
        rest = 'title\n=====\n\ntest'
        msgs = cmd._check_rst_data(rest)

            

Reported by Pylint.

Access to a protected member _check_rst_data of a client class
Error

Line: 86 Column: 16

              
        # and non-broken rest
        rest = 'title\n=====\n\ntest'
        msgs = cmd._check_rst_data(rest)
        self.assertEqual(len(msgs), 0)

    @unittest.skipUnless(HAS_DOCUTILS, "won't test without docutils")
    def test_check_restructuredtext(self):
        # let's see if it detects broken rest in long_description

            

Reported by Pylint.

Unused variable 'pkg_info'
Error

Line: 93 Column: 9

                  def test_check_restructuredtext(self):
        # let's see if it detects broken rest in long_description
        broken_rest = 'title\n===\n\ntest'
        pkg_info, dist = self.create_dist(long_description=broken_rest)
        cmd = check(dist)
        cmd.check_restructuredtext()
        self.assertEqual(cmd._warnings, 1)

        # let's see if we have an error with strict=1

            

Reported by Pylint.

Access to a protected member _warnings of a client class
Error

Line: 96 Column: 26

                      pkg_info, dist = self.create_dist(long_description=broken_rest)
        cmd = check(dist)
        cmd.check_restructuredtext()
        self.assertEqual(cmd._warnings, 1)

        # let's see if we have an error with strict=1
        metadata = {'url': 'xxx', 'author': 'xxx',
                    'author_email': 'xxx',
                    'name': 'xxx', 'version': 'xxx',

            

Reported by Pylint.

Lib/heapq.py
22 issues
Redefining built-in 'next'
Error

Line: 349 Column: 17

                  if key is None:
        for order, it in enumerate(map(iter, iterables)):
            try:
                next = it.__next__
                h_append([next(), order * direction, next])
            except StopIteration:
                pass
        _heapify(h)
        while len(h) > 1:

            

Reported by Pylint.

Unused variable 'key_value'
Error

Line: 381 Column: 17

                  while len(h) > 1:
        try:
            while True:
                key_value, order, value, next = s = h[0]
                yield value
                value = next()
                s[0] = key(value)
                s[2] = value
                _heapreplace(h, s)

            

Reported by Pylint.

Wildcard import _heapq
Error

Line: 581 Column: 5

              
# If available, use C implementation
try:
    from _heapq import *
except ImportError:
    pass
try:
    from _heapq import _heapreplace_max
except ImportError:

            

Reported by Pylint.

Argument name "x" doesn't conform to snake_case naming style
Error

Line: 168 Column: 1

                      _siftup(heap, 0)
    return item

def heapify(x):
    """Transform list into a heap, in-place, in O(len(x)) time."""
    n = len(x)
    # Transform bottom-up.  The largest index there's any point to looking at
    # is the largest with a child index in-range, so must have 2*i + 1 < n,
    # or i < (n-1)/2.  If n is even = 2*j, this is (2*j-1)/2 = j-1/2 so

            

Reported by Pylint.

Variable name "n" doesn't conform to snake_case naming style
Error

Line: 170 Column: 5

              
def heapify(x):
    """Transform list into a heap, in-place, in O(len(x)) time."""
    n = len(x)
    # Transform bottom-up.  The largest index there's any point to looking at
    # is the largest with a child index in-range, so must have 2*i + 1 < n,
    # or i < (n-1)/2.  If n is even = 2*j, this is (2*j-1)/2 = j-1/2 so
    # j-1 is the largest, which is n//2 - 1.  If n is odd = 2*j+1, this is
    # (2*j+1-1)/2 = j so j-1 is the largest, and that's again n//2-1.

            

Reported by Pylint.

Argument name "x" doesn't conform to snake_case naming style
Error

Line: 196 Column: 1

                  _siftup_max(heap, 0)
    return returnitem

def _heapify_max(x):
    """Transform list into a maxheap, in-place, in O(len(x)) time."""
    n = len(x)
    for i in reversed(range(n//2)):
        _siftup_max(x, i)


            

Reported by Pylint.

Variable name "n" doesn't conform to snake_case naming style
Error

Line: 198 Column: 5

              
def _heapify_max(x):
    """Transform list into a maxheap, in-place, in O(len(x)) time."""
    n = len(x)
    for i in reversed(range(n//2)):
        _siftup_max(x, i)

# 'heap' is a heap at all indices >= startpos, except possibly for pos.  pos
# is the index of a leaf with a possibly out-of-order value.  Restore the

            

Reported by Pylint.

Too many branches (15/12)
Error

Line: 314 Column: 1

                  heap[pos] = newitem
    _siftdown_max(heap, startpos, pos)

def merge(*iterables, key=None, reverse=False):
    '''Merge multiple sorted inputs into a single sorted output.

    Similar to sorted(itertools.chain(*iterables)) but returns a generator,
    does not pull the data into memory all at once, and assumes that each of
    the input streams is already sorted (smallest to largest).

            

Reported by Pylint.

Too many statements (51/50)
Error

Line: 314 Column: 1

                  heap[pos] = newitem
    _siftdown_max(heap, startpos, pos)

def merge(*iterables, key=None, reverse=False):
    '''Merge multiple sorted inputs into a single sorted output.

    Similar to sorted(itertools.chain(*iterables)) but returns a generator,
    does not pull the data into memory all at once, and assumes that each of
    the input streams is already sorted (smallest to largest).

            

Reported by Pylint.

Variable name "h" doesn't conform to snake_case naming style
Error

Line: 332 Column: 5

              
    '''

    h = []
    h_append = h.append

    if reverse:
        _heapify = _heapify_max
        _heappop = _heappop_max

            

Reported by Pylint.

Lib/lib2to3/fixes/fix_except.py
22 issues
Attempted relative import beyond top-level package
Error

Line: 25 Column: 1

              # Author: Collin Winter

# Local imports
from .. import pytree
from ..pgen2 import token
from .. import fixer_base
from ..fixer_util import Assign, Attr, Name, is_tuple, is_list, syms

def find_excepts(nodes):

            

Reported by Pylint.

Attempted relative import beyond top-level package
Error

Line: 26 Column: 1

              
# Local imports
from .. import pytree
from ..pgen2 import token
from .. import fixer_base
from ..fixer_util import Assign, Attr, Name, is_tuple, is_list, syms

def find_excepts(nodes):
    for i, n in enumerate(nodes):

            

Reported by Pylint.

Attempted relative import beyond top-level package
Error

Line: 27 Column: 1

              # Local imports
from .. import pytree
from ..pgen2 import token
from .. import fixer_base
from ..fixer_util import Assign, Attr, Name, is_tuple, is_list, syms

def find_excepts(nodes):
    for i, n in enumerate(nodes):
        if n.type == syms.except_clause:

            

Reported by Pylint.

Attempted relative import beyond top-level package
Error

Line: 28 Column: 1

              from .. import pytree
from ..pgen2 import token
from .. import fixer_base
from ..fixer_util import Assign, Attr, Name, is_tuple, is_list, syms

def find_excepts(nodes):
    for i, n in enumerate(nodes):
        if n.type == syms.except_clause:
            if n.children[0].value == 'except':

            

Reported by Pylint.

Redefining name 'syms' from outer scope (line 28)
Error

Line: 48 Column: 9

                  """

    def transform(self, node, results):
        syms = self.syms

        tail = [n.clone() for n in results["tail"]]

        try_cleanup = [ch.clone() for ch in results["cleanup"]]
        for except_clause, e_suite in find_excepts(try_cleanup):

            

Reported by Pylint.

Unused variable 'syms'
Error

Line: 48 Column: 9

                  """

    def transform(self, node, results):
        syms = self.syms

        tail = [n.clone() for n in results["tail"]]

        try_cleanup = [ch.clone() for ch in results["cleanup"]]
        for except_clause, e_suite in find_excepts(try_cleanup):

            

Reported by Pylint.

Unused variable 'E'
Error

Line: 55 Column: 18

                      try_cleanup = [ch.clone() for ch in results["cleanup"]]
        for except_clause, e_suite in find_excepts(try_cleanup):
            if len(except_clause.children) == 4:
                (E, comma, N) = except_clause.children[1:4]
                comma.replace(Name("as", prefix=" "))

                if N.type != token.NAME:
                    # Generate a new N for the except clause
                    new_N = Name(self.new_name(), prefix=" ")

            

Reported by Pylint.

TODO(cwinter) suite-cleanup
Error

Line: 69 Column: 2

                                  # Insert "old_N = new_N" as the first statement in
                    #  the except body. This loop skips leading whitespace
                    #  and indents
                    #TODO(cwinter) suite-cleanup
                    suite_stmts = e_suite.children
                    for i, stmt in enumerate(suite_stmts):
                        if isinstance(stmt, pytree.Node):
                            break


            

Reported by Pylint.

TODO(cwinter) stopgap until children becomes a smart list
Error

Line: 82 Column: 2

                                  else:
                        assign = Assign(target, new_N)

                    #TODO(cwinter) stopgap until children becomes a smart list
                    for child in reversed(suite_stmts[:i]):
                        e_suite.insert_child(0, child)
                    e_suite.insert_child(i, assign)
                elif N.prefix == "":
                    # No space after a comma is legal; no space after "as",

            

Reported by Pylint.

Using possibly undefined loop variable 'i'
Error

Line: 83 Column: 56

                                      assign = Assign(target, new_N)

                    #TODO(cwinter) stopgap until children becomes a smart list
                    for child in reversed(suite_stmts[:i]):
                        e_suite.insert_child(0, child)
                    e_suite.insert_child(i, assign)
                elif N.prefix == "":
                    # No space after a comma is legal; no space after "as",
                    # not so much.

            

Reported by Pylint.

Lib/asyncio/futures.py
22 issues
Attempted relative import beyond top-level package
Error

Line: 12 Column: 1

              import logging
import sys

from . import base_futures
from . import events
from . import exceptions
from . import format_helpers



            

Reported by Pylint.

Attempted relative import beyond top-level package
Error

Line: 13 Column: 1

              import sys

from . import base_futures
from . import events
from . import exceptions
from . import format_helpers


isfuture = base_futures.isfuture

            

Reported by Pylint.

Attempted relative import beyond top-level package
Error

Line: 14 Column: 1

              
from . import base_futures
from . import events
from . import exceptions
from . import format_helpers


isfuture = base_futures.isfuture


            

Reported by Pylint.

Attempted relative import beyond top-level package
Error

Line: 15 Column: 1

              from . import base_futures
from . import events
from . import exceptions
from . import format_helpers


isfuture = base_futures.isfuture



            

Reported by Pylint.

Access to a protected member _PENDING of a client class
Error

Line: 21 Column: 12

              isfuture = base_futures.isfuture


_PENDING = base_futures._PENDING
_CANCELLED = base_futures._CANCELLED
_FINISHED = base_futures._FINISHED


STACK_DEBUG = logging.DEBUG - 1  # heavy-duty debugging

            

Reported by Pylint.

Access to a protected member _CANCELLED of a client class
Error

Line: 22 Column: 14

              

_PENDING = base_futures._PENDING
_CANCELLED = base_futures._CANCELLED
_FINISHED = base_futures._FINISHED


STACK_DEBUG = logging.DEBUG - 1  # heavy-duty debugging


            

Reported by Pylint.

Access to a protected member _FINISHED of a client class
Error

Line: 23 Column: 13

              
_PENDING = base_futures._PENDING
_CANCELLED = base_futures._CANCELLED
_FINISHED = base_futures._FINISHED


STACK_DEBUG = logging.DEBUG - 1  # heavy-duty debugging



            

Reported by Pylint.

Access to a protected member _future_repr_info of a client class
Error

Line: 87 Column: 18

                          self._source_traceback = format_helpers.extract_stack(
                sys._getframe(1))

    _repr_info = base_futures._future_repr_info

    def __repr__(self):
        return '<{} {}>'.format(self.__class__.__name__,
                                ' '.join(self._repr_info()))


            

Reported by Pylint.

Unused argument 'type'
Error

Line: 109 Column: 32

                          context['source_traceback'] = self._source_traceback
        self._loop.call_exception_handler(context)

    def __class_getitem__(cls, type):
        return cls

    @property
    def _log_traceback(self):
        return self.__log_traceback

            

Reported by Pylint.

Redefining built-in 'type'
Error

Line: 109 Column: 32

                          context['source_traceback'] = self._source_traceback
        self._loop.call_exception_handler(context)

    def __class_getitem__(cls, type):
        return cls

    @property
    def _log_traceback(self):
        return self.__log_traceback

            

Reported by Pylint.

Lib/distutils/filelist.py
22 issues
Unused argument 'warn'
Error

Line: 29 Column: 24

                      filtering applied)
    """

    def __init__(self, warn=None, debug_print=None):
        # ignore argument to FileList, but keep them for backwards
        # compatibility
        self.allfiles = None
        self.files = []


            

Reported by Pylint.

Unused argument 'debug_print'
Error

Line: 29 Column: 35

                      filtering applied)
    """

    def __init__(self, warn=None, debug_print=None):
        # ignore argument to FileList, but keep them for backwards
        # compatibility
        self.allfiles = None
        self.files = []


            

Reported by Pylint.

Redefining built-in 'dir'
Error

Line: 38 Column: 23

                  def set_allfiles(self, allfiles):
        self.allfiles = allfiles

    def findall(self, dir=os.curdir):
        self.allfiles = findall(dir)

    def debug_print(self, msg):
        """Print 'msg' to stdout if the global DEBUG (taken from the
        DISTUTILS_DEBUG environment variable) flag is true.

            

Reported by Pylint.

Redefining built-in 'dir'
Error

Line: 80 Column: 20

                      words = line.split()
        action = words[0]

        patterns = dir = dir_pattern = None

        if action in ('include', 'exclude',
                      'global-include', 'global-exclude'):
            if len(words) < 2:
                raise DistutilsTemplateError(

            

Reported by Pylint.

Redefining built-in 'dir'
Error

Line: 110 Column: 28

                      # defined: it's the first word of the line.  Which of the other
        # three are defined depends on the action; it'll be either
        # patterns, (dir and patterns), or (dir_pattern).
        (action, patterns, dir, dir_pattern) = self._parse_template_line(line)

        # OK, now we know that the action is valid and we have the
        # right number of words on the line for that action -- so we
        # can proceed with minimal error-checking.
        if action == 'include':

            

Reported by Pylint.

XXX docstring lying about what the special chars are?
Error

Line: 205 Column: 3

              
        Return True if files are found, False otherwise.
        """
        # XXX docstring lying about what the special chars are?
        files_found = False
        pattern_re = translate_pattern(pattern, anchor, prefix, is_regex)
        self.debug_print("include_pattern: applying regex r'%s'" %
                         pattern_re.pattern)


            

Reported by Pylint.

Redefining built-in 'dir'
Error

Line: 258 Column: 13

                  return filter(os.path.isfile, results)


def findall(dir=os.curdir):
    """
    Find all files under 'dir' and return the list of full filenames.
    Unless dir is '.', return full filenames with dir prepended.
    """
    files = _find_all_simple(dir)

            

Reported by Pylint.

Multiple imports on one line (os, re)
Error

Line: 7 Column: 1

              and building lists of files.
"""

import os, re
import fnmatch
import functools
from distutils.util import convert_path
from distutils.errors import DistutilsTemplateError, DistutilsInternalError
from distutils import log

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 35 Column: 5

                      self.allfiles = None
        self.files = []

    def set_allfiles(self, allfiles):
        self.allfiles = allfiles

    def findall(self, dir=os.curdir):
        self.allfiles = findall(dir)


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 38 Column: 5

                  def set_allfiles(self, allfiles):
        self.allfiles = allfiles

    def findall(self, dir=os.curdir):
        self.allfiles = findall(dir)

    def debug_print(self, msg):
        """Print 'msg' to stdout if the global DEBUG (taken from the
        DISTUTILS_DEBUG environment variable) flag is true.

            

Reported by Pylint.

Lib/asyncio/trsock.py
22 issues
Missing module docstring
Error

Line: 1 Column: 1

              import socket


class TransportSocket:

    """A socket-like wrapper for exposing real transport sockets.

    These objects can be safely returned by APIs like
    `transport.get_extra_info('socket')`.  All potentially disruptive

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 19 Column: 5

                      self._sock = sock

    @property
    def family(self):
        return self._sock.family

    @property
    def type(self):
        return self._sock.type

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 23 Column: 5

                      return self._sock.family

    @property
    def type(self):
        return self._sock.type

    @property
    def proto(self):
        return self._sock.proto

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 27 Column: 5

                      return self._sock.type

    @property
    def proto(self):
        return self._sock.proto

    def __repr__(self):
        s = (
            f"<asyncio.TransportSocket fd={self.fileno()}, "

            

Reported by Pylint.

Variable name "s" doesn't conform to snake_case naming style
Error

Line: 31 Column: 9

                      return self._sock.proto

    def __repr__(self):
        s = (
            f"<asyncio.TransportSocket fd={self.fileno()}, "
            f"family={self.family!s}, type={self.type!s}, "
            f"proto={self.proto}"
        )


            

Reported by Pylint.

Variable name "s" doesn't conform to snake_case naming style
Error

Line: 41 Column: 21

                          try:
                laddr = self.getsockname()
                if laddr:
                    s = f"{s}, laddr={laddr}"
            except socket.error:
                pass
            try:
                raddr = self.getpeername()
                if raddr:

            

Reported by Pylint.

Variable name "s" doesn't conform to snake_case naming style
Error

Line: 47 Column: 21

                          try:
                raddr = self.getpeername()
                if raddr:
                    s = f"{s}, raddr={raddr}"
            except socket.error:
                pass

        return f"{s}>"


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 56 Column: 5

                  def __getstate__(self):
        raise TypeError("Cannot serialize asyncio.TransportSocket object")

    def fileno(self):
        return self._sock.fileno()

    def dup(self):
        return self._sock.dup()


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 59 Column: 5

                  def fileno(self):
        return self._sock.fileno()

    def dup(self):
        return self._sock.dup()

    def get_inheritable(self):
        return self._sock.get_inheritable()


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 62 Column: 5

                  def dup(self):
        return self._sock.dup()

    def get_inheritable(self):
        return self._sock.get_inheritable()

    def shutdown(self, how):
        # asyncio doesn't currently provide a high-level transport API
        # to shutdown the connection.

            

Reported by Pylint.

Lib/encodings/bz2_codec.py
22 issues
Redefining built-in 'input'
Error

Line: 15 Column: 16

              
### Codec APIs

def bz2_encode(input, errors='strict'):
    assert errors == 'strict'
    return (bz2.compress(input), len(input))

def bz2_decode(input, errors='strict'):
    assert errors == 'strict'

            

Reported by Pylint.

Redefining built-in 'input'
Error

Line: 19 Column: 16

                  assert errors == 'strict'
    return (bz2.compress(input), len(input))

def bz2_decode(input, errors='strict'):
    assert errors == 'strict'
    return (bz2.decompress(input), len(input))

class Codec(codecs.Codec):
    def encode(self, input, errors='strict'):

            

Reported by Pylint.

Redefining built-in 'input'
Error

Line: 24 Column: 22

                  return (bz2.decompress(input), len(input))

class Codec(codecs.Codec):
    def encode(self, input, errors='strict'):
        return bz2_encode(input, errors)
    def decode(self, input, errors='strict'):
        return bz2_decode(input, errors)

class IncrementalEncoder(codecs.IncrementalEncoder):

            

Reported by Pylint.

Redefining built-in 'input'
Error

Line: 26 Column: 22

              class Codec(codecs.Codec):
    def encode(self, input, errors='strict'):
        return bz2_encode(input, errors)
    def decode(self, input, errors='strict'):
        return bz2_decode(input, errors)

class IncrementalEncoder(codecs.IncrementalEncoder):
    def __init__(self, errors='strict'):
        assert errors == 'strict'

            

Reported by Pylint.

__init__ method from base class 'IncrementalEncoder' is not called
Error

Line: 30 Column: 5

                      return bz2_decode(input, errors)

class IncrementalEncoder(codecs.IncrementalEncoder):
    def __init__(self, errors='strict'):
        assert errors == 'strict'
        self.errors = errors
        self.compressobj = bz2.BZ2Compressor()

    def encode(self, input, final=False):

            

Reported by Pylint.

Redefining built-in 'input'
Error

Line: 35 Column: 22

                      self.errors = errors
        self.compressobj = bz2.BZ2Compressor()

    def encode(self, input, final=False):
        if final:
            c = self.compressobj.compress(input)
            return c + self.compressobj.flush()
        else:
            return self.compressobj.compress(input)

            

Reported by Pylint.

__init__ method from base class 'IncrementalDecoder' is not called
Error

Line: 46 Column: 5

                      self.compressobj = bz2.BZ2Compressor()

class IncrementalDecoder(codecs.IncrementalDecoder):
    def __init__(self, errors='strict'):
        assert errors == 'strict'
        self.errors = errors
        self.decompressobj = bz2.BZ2Decompressor()

    def decode(self, input, final=False):

            

Reported by Pylint.

Redefining built-in 'input'
Error

Line: 51 Column: 22

                      self.errors = errors
        self.decompressobj = bz2.BZ2Decompressor()

    def decode(self, input, final=False):
        try:
            return self.decompressobj.decompress(input)
        except EOFError:
            return ''


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 15 Column: 1

              
### Codec APIs

def bz2_encode(input, errors='strict'):
    assert errors == 'strict'
    return (bz2.compress(input), len(input))

def bz2_decode(input, errors='strict'):
    assert errors == 'strict'

            

Reported by Pylint.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 16
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

              ### Codec APIs

def bz2_encode(input, errors='strict'):
    assert errors == 'strict'
    return (bz2.compress(input), len(input))

def bz2_decode(input, errors='strict'):
    assert errors == 'strict'
    return (bz2.decompress(input), len(input))

            

Reported by Bandit.

Lib/distutils/tests/test_upload.py
22 issues
Unused variable 'pkg_dir'
Error

Line: 125 Column: 9

                      self.write_file(self.rc, PYPIRC_LONG_PASSWORD)

        # lets run it
        pkg_dir, dist = self.create_dist(dist_files=dist_files)
        cmd = upload(dist)
        cmd.show_response = 1
        cmd.ensure_finalized()
        cmd.run()


            

Reported by Pylint.

Unused variable 'pkg_dir'
Error

Line: 175 Column: 9

              
        # other fields that ended with \r used to be modified, now are
        # preserved.
        pkg_dir, dist = self.create_dist(
            dist_files=dist_files,
            description='long description\r'
        )
        cmd = upload(dist)
        cmd.show_response = 1

            

Reported by Pylint.

Unused variable 'pkg_dir'
Error

Line: 200 Column: 9

                      dist_files = [('xxx', '2.6', path)]  # command, pyversion, filename
        self.write_file(self.rc, PYPIRC_LONG_PASSWORD)

        pkg_dir, dist = self.create_dist(dist_files=dist_files)
        tests = [
            (OSError('oserror'), 'oserror', OSError),
            (HTTPError('url', 400, 'httperror', {}, None),
             'Upload failed (400): httperror', DistutilsError),
        ]

            

Reported by Pylint.

Possible hardcoded password: '[distutils] index-servers = server1 server2 [server1] username:me password:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa [server2] username:meagain password: secret realm:acme repository:http://another.pypi/ '
Security

Line: 17
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b105_hardcoded_password_string.html

              
from distutils.tests.test_config import PYPIRC, BasePyPIRCCommandTestCase

PYPIRC_LONG_PASSWORD = """\
[distutils]

index-servers =
    server1
    server2

            

Reported by Bandit.

Class 'FakeOpen' inherits from object, can be safely removed from bases in python3
Error

Line: 46 Column: 1

              username:me
"""

class FakeOpen(object):

    def __init__(self, url, msg=None, code=None):
        self.url = url
        if not isinstance(url, str):
            self.req = url

            

Reported by Pylint.

Missing class docstring
Error

Line: 46 Column: 1

              username:me
"""

class FakeOpen(object):

    def __init__(self, url, msg=None, code=None):
        self.url = url
        if not isinstance(url, str):
            self.req = url

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 57 Column: 5

                      self.msg = msg or 'OK'
        self.code = code or 200

    def getheader(self, name, default=None):
        return {
            'content-type': 'text/plain; charset=utf-8',
            }.get(name.lower(), default)

    def read(self):

            

Reported by Pylint.

Method could be a function
Error

Line: 57 Column: 5

                      self.msg = msg or 'OK'
        self.code = code or 200

    def getheader(self, name, default=None):
        return {
            'content-type': 'text/plain; charset=utf-8',
            }.get(name.lower(), default)

    def read(self):

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 62 Column: 5

                          'content-type': 'text/plain; charset=utf-8',
            }.get(name.lower(), default)

    def read(self):
        return b'xyzzy'

    def getcode(self):
        return self.code


            

Reported by Pylint.

Method could be a function
Error

Line: 62 Column: 5

                          'content-type': 'text/plain; charset=utf-8',
            }.get(name.lower(), default)

    def read(self):
        return b'xyzzy'

    def getcode(self):
        return self.code


            

Reported by Pylint.