The following issues were found

Lib/test/test_flufl.py
7 issues
Unused support imported from test
Error

Line: 3 Column: 1

              import __future__
import unittest
from test import support


class FLUFLTests(unittest.TestCase):

    def test_barry_as_bdfl(self):
        code = "from __future__ import barry_as_FLUFL\n2 {0} 3"

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import __future__
import unittest
from test import support


class FLUFLTests(unittest.TestCase):

    def test_barry_as_bdfl(self):
        code = "from __future__ import barry_as_FLUFL\n2 {0} 3"

            

Reported by Pylint.

Missing class docstring
Error

Line: 6 Column: 1

              from test import support


class FLUFLTests(unittest.TestCase):

    def test_barry_as_bdfl(self):
        code = "from __future__ import barry_as_FLUFL\n2 {0} 3"
        compile(code.format('<>'), '<BDFL test>', 'exec',
                __future__.CO_FUTURE_BARRY_AS_BDFL)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 8 Column: 5

              
class FLUFLTests(unittest.TestCase):

    def test_barry_as_bdfl(self):
        code = "from __future__ import barry_as_FLUFL\n2 {0} 3"
        compile(code.format('<>'), '<BDFL test>', 'exec',
                __future__.CO_FUTURE_BARRY_AS_BDFL)
        with self.assertRaises(SyntaxError) as cm:
            compile(code.format('!='), '<FLUFL test>', 'exec',

            

Reported by Pylint.

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

Line: 12 Column: 48

                      code = "from __future__ import barry_as_FLUFL\n2 {0} 3"
        compile(code.format('<>'), '<BDFL test>', 'exec',
                __future__.CO_FUTURE_BARRY_AS_BDFL)
        with self.assertRaises(SyntaxError) as cm:
            compile(code.format('!='), '<FLUFL test>', 'exec',
                    __future__.CO_FUTURE_BARRY_AS_BDFL)
        self.assertRegex(str(cm.exception),
                         "with Barry as BDFL, use '<>' instead of '!='")
        self.assertIn('2 != 3', cm.exception.text)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 25 Column: 5

                      # parser reports the start of the token
        self.assertEqual(cm.exception.offset, 3)

    def test_guido_as_bdfl(self):
        code = '2 {0} 3'
        compile(code.format('!='), '<BDFL test>', 'exec')
        with self.assertRaises(SyntaxError) as cm:
            compile(code.format('<>'), '<FLUFL test>', 'exec')
        self.assertRegex(str(cm.exception), "invalid syntax")

            

Reported by Pylint.

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

Line: 28 Column: 48

                  def test_guido_as_bdfl(self):
        code = '2 {0} 3'
        compile(code.format('!='), '<BDFL test>', 'exec')
        with self.assertRaises(SyntaxError) as cm:
            compile(code.format('<>'), '<FLUFL test>', 'exec')
        self.assertRegex(str(cm.exception), "invalid syntax")
        self.assertIn('2 <> 3', cm.exception.text)
        self.assertEqual(cm.exception.filename, '<FLUFL test>')
        self.assertEqual(cm.exception.lineno, 1)

            

Reported by Pylint.

Lib/test/test_longexp.py
7 issues
Use of eval
Error

Line: 6 Column: 13

              class LongExpText(unittest.TestCase):
    def test_longexp(self):
        REPS = 65580
        l = eval("[" + "2," * REPS + "]")
        self.assertEqual(len(l), REPS)

if __name__ == "__main__":
    unittest.main()

            

Reported by Pylint.

Use of possibly insecure function - consider using safer ast.literal_eval.
Security blacklist

Line: 6
Suggestion: https://bandit.readthedocs.io/en/latest/blacklists/blacklist_calls.html#b307-eval

              class LongExpText(unittest.TestCase):
    def test_longexp(self):
        REPS = 65580
        l = eval("[" + "2," * REPS + "]")
        self.assertEqual(len(l), REPS)

if __name__ == "__main__":
    unittest.main()

            

Reported by Bandit.

Missing module docstring
Error

Line: 1 Column: 1

              import unittest

class LongExpText(unittest.TestCase):
    def test_longexp(self):
        REPS = 65580
        l = eval("[" + "2," * REPS + "]")
        self.assertEqual(len(l), REPS)

if __name__ == "__main__":

            

Reported by Pylint.

Missing class docstring
Error

Line: 3 Column: 1

              import unittest

class LongExpText(unittest.TestCase):
    def test_longexp(self):
        REPS = 65580
        l = eval("[" + "2," * REPS + "]")
        self.assertEqual(len(l), REPS)

if __name__ == "__main__":

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 4 Column: 5

              import unittest

class LongExpText(unittest.TestCase):
    def test_longexp(self):
        REPS = 65580
        l = eval("[" + "2," * REPS + "]")
        self.assertEqual(len(l), REPS)

if __name__ == "__main__":

            

Reported by Pylint.

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

Line: 5 Column: 9

              
class LongExpText(unittest.TestCase):
    def test_longexp(self):
        REPS = 65580
        l = eval("[" + "2," * REPS + "]")
        self.assertEqual(len(l), REPS)

if __name__ == "__main__":
    unittest.main()

            

Reported by Pylint.

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

Line: 6 Column: 9

              class LongExpText(unittest.TestCase):
    def test_longexp(self):
        REPS = 65580
        l = eval("[" + "2," * REPS + "]")
        self.assertEqual(len(l), REPS)

if __name__ == "__main__":
    unittest.main()

            

Reported by Pylint.

Lib/test/test_check_c_globals.py
7 issues
Unable to import 'cpython.__main__'
Error

Line: 6 Column: 5

              
test.test_tools.skip_if_missing('c-analyzer')
with test.test_tools.imports_under_tool('c-analyzer'):
    from cpython.__main__ import main


class ActualChecks(unittest.TestCase):

    # XXX Also run the check in "make check".

            

Reported by Pylint.

XXX Also run the check in "make check".
Error

Line: 11 Column: 3

              
class ActualChecks(unittest.TestCase):

    # XXX Also run the check in "make check".
    #@unittest.expectedFailure
    # Failing on one of the buildbots (see https://bugs.python.org/issue36876).
    @unittest.skip('activate this once all the globals have been resolved')
    def test_check_c_globals(self):
        try:

            

Reported by Pylint.

Consider explicitly re-raising using the 'from' keyword
Error

Line: 19 Column: 13

                      try:
            main('check', {})
        except NotImplementedError:
            raise unittest.SkipTest('not supported on this host')


if __name__ == '__main__':
    # Test needs to be a package, so we can do relative imports.
    unittest.main()

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import unittest
import test.test_tools

test.test_tools.skip_if_missing('c-analyzer')
with test.test_tools.imports_under_tool('c-analyzer'):
    from cpython.__main__ import main


class ActualChecks(unittest.TestCase):

            

Reported by Pylint.

Missing class docstring
Error

Line: 9 Column: 1

                  from cpython.__main__ import main


class ActualChecks(unittest.TestCase):

    # XXX Also run the check in "make check".
    #@unittest.expectedFailure
    # Failing on one of the buildbots (see https://bugs.python.org/issue36876).
    @unittest.skip('activate this once all the globals have been resolved')

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 15 Column: 5

                  #@unittest.expectedFailure
    # Failing on one of the buildbots (see https://bugs.python.org/issue36876).
    @unittest.skip('activate this once all the globals have been resolved')
    def test_check_c_globals(self):
        try:
            main('check', {})
        except NotImplementedError:
            raise unittest.SkipTest('not supported on this host')


            

Reported by Pylint.

Method could be a function
Error

Line: 15 Column: 5

                  #@unittest.expectedFailure
    # Failing on one of the buildbots (see https://bugs.python.org/issue36876).
    @unittest.skip('activate this once all the globals have been resolved')
    def test_check_c_globals(self):
        try:
            main('check', {})
        except NotImplementedError:
            raise unittest.SkipTest('not supported on this host')


            

Reported by Pylint.

Lib/test/badsyntax_future3.py
7 issues
No name 'rested_snopes' in module '__future__'
Error

Line: 3 Column: 1

              """This is a test"""
from __future__ import nested_scopes
from __future__ import rested_snopes

def f(x):
    def g(y):
        return x + y
    return g


            

Reported by Pylint.

Function name "f" doesn't conform to snake_case naming style
Error

Line: 5 Column: 1

              from __future__ import nested_scopes
from __future__ import rested_snopes

def f(x):
    def g(y):
        return x + y
    return g

result = f(2)(4)

            

Reported by Pylint.

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

Line: 5 Column: 1

              from __future__ import nested_scopes
from __future__ import rested_snopes

def f(x):
    def g(y):
        return x + y
    return g

result = f(2)(4)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 5 Column: 1

              from __future__ import nested_scopes
from __future__ import rested_snopes

def f(x):
    def g(y):
        return x + y
    return g

result = f(2)(4)

            

Reported by Pylint.

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

Line: 6 Column: 5

              from __future__ import rested_snopes

def f(x):
    def g(y):
        return x + y
    return g

result = f(2)(4)

            

Reported by Pylint.

Function name "g" doesn't conform to snake_case naming style
Error

Line: 6 Column: 5

              from __future__ import rested_snopes

def f(x):
    def g(y):
        return x + y
    return g

result = f(2)(4)

            

Reported by Pylint.

Constant name "result" doesn't conform to UPPER_CASE naming style
Error

Line: 10 Column: 1

                      return x + y
    return g

result = f(2)(4)

            

Reported by Pylint.

Lib/test/dis_module.py
7 issues
Missing module docstring
Error

Line: 1 Column: 1

              
# A simple module for testing the dis module.

def f(): pass
def g(): pass

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 4 Column: 1

              
# A simple module for testing the dis module.

def f(): pass
def g(): pass

            

Reported by Pylint.

Function name "f" doesn't conform to snake_case naming style
Error

Line: 4 Column: 1

              
# A simple module for testing the dis module.

def f(): pass
def g(): pass

            

Reported by Pylint.

More than one statement on a single line
Error

Line: 4 Column: 10

              
# A simple module for testing the dis module.

def f(): pass
def g(): pass

            

Reported by Pylint.

More than one statement on a single line
Error

Line: 5 Column: 10

              # A simple module for testing the dis module.

def f(): pass
def g(): pass

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 5 Column: 1

              # A simple module for testing the dis module.

def f(): pass
def g(): pass

            

Reported by Pylint.

Function name "g" doesn't conform to snake_case naming style
Error

Line: 5 Column: 1

              # A simple module for testing the dis module.

def f(): pass
def g(): pass

            

Reported by Pylint.

Lib/test/leakers/test_selftype.py
7 issues
Missing module docstring
Error

Line: 1 Column: 1

              # Reference cycles involving only the ob_type field are rather uncommon
# but possible.  Inspired by SF bug 1469629.

import gc

def leak():
    class T(type):
        pass
    class U(type, metaclass=T):

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 6 Column: 1

              
import gc

def leak():
    class T(type):
        pass
    class U(type, metaclass=T):
        pass
    U.__class__ = U

            

Reported by Pylint.

Class name "T" doesn't conform to PascalCase naming style
Error

Line: 7 Column: 5

              import gc

def leak():
    class T(type):
        pass
    class U(type, metaclass=T):
        pass
    U.__class__ = U
    del U

            

Reported by Pylint.

Missing class docstring
Error

Line: 7 Column: 5

              import gc

def leak():
    class T(type):
        pass
    class U(type, metaclass=T):
        pass
    U.__class__ = U
    del U

            

Reported by Pylint.

Class name "U" doesn't conform to PascalCase naming style
Error

Line: 9 Column: 5

              def leak():
    class T(type):
        pass
    class U(type, metaclass=T):
        pass
    U.__class__ = U
    del U
    gc.collect(); gc.collect(); gc.collect()

            

Reported by Pylint.

Missing class docstring
Error

Line: 9 Column: 5

              def leak():
    class T(type):
        pass
    class U(type, metaclass=T):
        pass
    U.__class__ = U
    del U
    gc.collect(); gc.collect(); gc.collect()

            

Reported by Pylint.

More than one statement on a single line
Error

Line: 13 Column: 19

                      pass
    U.__class__ = U
    del U
    gc.collect(); gc.collect(); gc.collect()

            

Reported by Pylint.

Modules/_ctypes/_ctypes_test.c
7 issues
vprintf - If format strings can be influenced by an attacker, they can be exploited
Security

Line: 284 Column: 14 CWE codes: 134
Suggestion: Use a constant for the format specification

                  int result;
    va_list argptr;
    va_start(argptr, fmt);
    result = vprintf(fmt, argptr);
    va_end(argptr);
    return result;
}

EXPORT(char *)my_strtok(char *token, const char *delim)

            

Reported by FlawFinder.

strcpy - Does not check for buffer overflows when copying to destination [MS-banned]
Security

Line: 372 Column: 5 CWE codes: 120
Suggestion: Consider using snprintf, strcpy_s, or strlcpy (warning: strncpy easily misused)

                  char *dst = (char *)malloc(strlen(src)+1);
    if (!dst)
        return NULL;
    strcpy(dst, src);
    return dst;
}

EXPORT(void)my_free(void *ptr)
{

            

Reported by FlawFinder.

char - Statically-sized arrays can be improperly restricted, leading to potential overflows or other issues
Security

Line: 78 Column: 14 CWE codes: 119 120
Suggestion: Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length

               */

typedef struct {
    unsigned char data[16];
} Test2;

EXPORT(int)
_testfunc_array_in_struct1(Test2 in)
{

            

Reported by FlawFinder.

memcpy - Does not check for buffer overflows when copying to destination
Security

Line: 388 Column: 5 CWE codes: 120
Suggestion: Make sure destination can always hold the source data

                  wchar_t *ptr = (wchar_t *)malloc((len + 1) * sizeof(wchar_t));
    if (ptr == NULL)
        return NULL;
    memcpy(ptr, src, (len+1) * sizeof(wchar_t));
    return ptr;
}

EXPORT(size_t) my_wcslen(wchar_t *src)
{

            

Reported by FlawFinder.

strlen - Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected)
Security

Line: 369 Column: 32 CWE codes: 126

              
EXPORT(char *) my_strdup(char *src)
{
    char *dst = (char *)malloc(strlen(src)+1);
    if (!dst)
        return NULL;
    strcpy(dst, src);
    return dst;
}

            

Reported by FlawFinder.

wcslen - Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected)
Security

Line: 384 Column: 18 CWE codes: 126

              #ifdef HAVE_WCHAR_H
EXPORT(wchar_t *) my_wcsdup(wchar_t *src)
{
    size_t len = wcslen(src);
    wchar_t *ptr = (wchar_t *)malloc((len + 1) * sizeof(wchar_t));
    if (ptr == NULL)
        return NULL;
    memcpy(ptr, src, (len+1) * sizeof(wchar_t));
    return ptr;

            

Reported by FlawFinder.

wcslen - Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected)
Security

Line: 394 Column: 12 CWE codes: 126

              
EXPORT(size_t) my_wcslen(wchar_t *src)
{
    return wcslen(src);
}
#endif

#ifndef MS_WIN32
# ifndef __stdcall

            

Reported by FlawFinder.

Tools/c-analyzer/cpython/_parser.py
7 issues
Attempted relative import beyond top-level package
Error

Line: 11 Column: 1

                  parse_file as _parse_file,
    parse_files as _parse_files,
)
from . import REPO_ROOT


GLOB_ALL = '**/*'



            

Reported by Pylint.

String statement has no effect
Error

Line: 29 Column: 1

                  return list(lines)


'''
@begin=sh@
./python ../c-parser/cpython.py
    --exclude '+../c-parser/EXCLUDED'
    --macros '+../c-parser/MACROS'
    --incldirs '+../c-parser/INCL_DIRS'

            

Reported by Pylint.

XXX Fix the parser.
Error

Line: 82 Column: 3

              # @end=conf@
''')

# XXX Fix the parser.
EXCLUDED += clean_lines('''
# The tool should be able to parse these...

Modules/hashlib.h
Objects/stringlib/codecs.h

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import os.path
import re

from c_parser.preprocessor import (
    get_preprocessor as _get_preprocessor,
)
from c_parser import (
    parse_file as _parse_file,
    parse_files as _parse_files,

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 269 Column: 1

              ]


def get_preprocessor(*,
                     file_macros=None,
                     file_incldirs=None,
                     file_same=None,
                     **kwargs
                     ):

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 289 Column: 1

                  )


def parse_file(filename, *,
               match_kind=None,
               ignore_exc=None,
               log_err=None,
               ):
    get_file_preprocessor = get_preprocessor(

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 305 Column: 1

                  )


def parse_files(filenames=None, *,
                match_kind=None,
                ignore_exc=None,
                log_err=None,
                get_file_preprocessor=None,
                **file_kwargs

            

Reported by Pylint.

Lib/test/test_wait3.py
7 issues
Module 'os' has no 'waitstatus_to_exitcode' member
Error

Line: 33 Column: 26

                          time.sleep(0.1)

        self.assertEqual(spid, cpid)
        self.assertEqual(os.waitstatus_to_exitcode(status), exitcode)
        self.assertTrue(rusage)

    def test_wait3_rusage_initialized(self):
        # Ensure a successful wait3() call where no child was ready to report
        # its exit status does not return uninitialized memory in the rusage

            

Reported by Pylint.

Consider possible security implications associated with subprocess module.
Security blacklist

Line: 5
Suggestion: https://bandit.readthedocs.io/en/latest/blacklists/blacklist_imports.html#b404-import-subprocess

              """

import os
import subprocess
import sys
import time
import unittest
from test.fork_wait import ForkWait
from test import support

            

Reported by Bandit.

Missing class docstring
Error

Line: 18 Column: 1

              if not hasattr(os, 'wait3'):
    raise unittest.SkipTest("os.wait3 not defined")

class Wait3Test(ForkWait):
    def wait_impl(self, cpid, *, exitcode):
        # This many iterations can be required, since some previously run
        # tests (e.g. test_ctypes) could have spawned a lot of children
        # very quickly.
        deadline = time.monotonic() + support.SHORT_TIMEOUT

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 36 Column: 5

                      self.assertEqual(os.waitstatus_to_exitcode(status), exitcode)
        self.assertTrue(rusage)

    def test_wait3_rusage_initialized(self):
        # Ensure a successful wait3() call where no child was ready to report
        # its exit status does not return uninitialized memory in the rusage
        # structure. See bpo-36279.
        args = [sys.executable, '-c', 'import sys; sys.stdin.read()']
        proc = subprocess.Popen(args, stdin=subprocess.PIPE)

            

Reported by Pylint.

subprocess call - check for execution of untrusted input.
Security injection

Line: 41
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b603_subprocess_without_shell_equals_true.html

                      # its exit status does not return uninitialized memory in the rusage
        # structure. See bpo-36279.
        args = [sys.executable, '-c', 'import sys; sys.stdin.read()']
        proc = subprocess.Popen(args, stdin=subprocess.PIPE)
        try:
            pid, status, rusage = os.wait3(os.WNOHANG)
            self.assertEqual(0, pid)
            self.assertEqual(0, status)
            self.assertEqual(0, sum(rusage))

            

Reported by Bandit.

Missing function or method docstring
Error

Line: 52 Column: 1

                          proc.wait()


def tearDownModule():
    support.reap_children()

if __name__ == "__main__":
    unittest.main()

            

Reported by Pylint.

Function name "tearDownModule" doesn't conform to snake_case naming style
Error

Line: 52 Column: 1

                          proc.wait()


def tearDownModule():
    support.reap_children()

if __name__ == "__main__":
    unittest.main()

            

Reported by Pylint.

Objects/typeslots.py
7 issues
Missing module docstring
Error

Line: 1 Column: 1

              #!/usr/bin/python
# Usage: typeslots.py < Include/typeslots.h typeslots.inc

import sys, re


def generate_typeslots(out=sys.stdout):
    out.write("/* Generated by typeslots.py */\n")
    res = {}

            

Reported by Pylint.

Multiple imports on one line (sys, re)
Error

Line: 4 Column: 1

              #!/usr/bin/python
# Usage: typeslots.py < Include/typeslots.h typeslots.inc

import sys, re


def generate_typeslots(out=sys.stdout):
    out.write("/* Generated by typeslots.py */\n")
    res = {}

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 7 Column: 1

              import sys, re


def generate_typeslots(out=sys.stdout):
    out.write("/* Generated by typeslots.py */\n")
    res = {}
    for line in sys.stdin:
        m = re.match("#define Py_([a-z_]+) ([0-9]+)", line)
        if not m:

            

Reported by Pylint.

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

Line: 11 Column: 9

                  out.write("/* Generated by typeslots.py */\n")
    res = {}
    for line in sys.stdin:
        m = re.match("#define Py_([a-z_]+) ([0-9]+)", line)
        if not m:
            continue

        member = m.group(1)
        if member.startswith("tp_"):

            

Reported by Pylint.

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

Line: 35 Column: 5

                                    ' offsetof(PyTypeObject, tp_as_buffer)}')
        res[int(m.group(2))] = member

    M = max(res.keys())+1
    for i in range(1,M):
        if i in res:
            out.write("%s,\n" % res[i])
        else:
            out.write("{0, 0},\n")

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 43 Column: 1

                          out.write("{0, 0},\n")


def main():
    if len(sys.argv) == 2:
        with open(sys.argv[1], "w") as f:
            generate_typeslots(f)
    else:
        generate_typeslots()

            

Reported by Pylint.

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

Line: 45 Column: 40

              
def main():
    if len(sys.argv) == 2:
        with open(sys.argv[1], "w") as f:
            generate_typeslots(f)
    else:
        generate_typeslots()

if __name__ == "__main__":

            

Reported by Pylint.