The following issues were found

Lib/ctypes/test/test_loading.py
108 issues
No name 'LoadLibrary' in module '_ctypes'
Error

Line: 91 Column: 9

              
    @unittest.skipUnless(os.name == "nt", 'Windows-specific test')
    def test_1703286_A(self):
        from _ctypes import LoadLibrary, FreeLibrary
        # On winXP 64-bit, advapi32 loads at an address that does
        # NOT fit into a 32-bit integer.  FreeLibrary must be able
        # to accept this address.

        # These are tests for https://www.python.org/sf/1703286

            

Reported by Pylint.

No name 'FreeLibrary' in module '_ctypes'
Error

Line: 91 Column: 9

              
    @unittest.skipUnless(os.name == "nt", 'Windows-specific test')
    def test_1703286_A(self):
        from _ctypes import LoadLibrary, FreeLibrary
        # On winXP 64-bit, advapi32 loads at an address that does
        # NOT fit into a 32-bit integer.  FreeLibrary must be able
        # to accept this address.

        # These are tests for https://www.python.org/sf/1703286

            

Reported by Pylint.

Unused import FormatError from wildcard import
Error

Line: 1 Column: 1

              from ctypes import *
import os
import shutil
import subprocess
import sys
import unittest
import test.support
from test.support import import_helper
from test.support import os_helper

            

Reported by Pylint.

Unused import ArgumentError from wildcard import
Error

Line: 1 Column: 1

              from ctypes import *
import os
import shutil
import subprocess
import sys
import unittest
import test.support
from test.support import import_helper
from test.support import os_helper

            

Reported by Pylint.

Unused import RTLD_GLOBAL from wildcard import
Error

Line: 1 Column: 1

              from ctypes import *
import os
import shutil
import subprocess
import sys
import unittest
import test.support
from test.support import import_helper
from test.support import os_helper

            

Reported by Pylint.

Unused import RTLD_LOCAL from wildcard import
Error

Line: 1 Column: 1

              from ctypes import *
import os
import shutil
import subprocess
import sys
import unittest
import test.support
from test.support import import_helper
from test.support import os_helper

            

Reported by Pylint.

Unused import Array from wildcard import
Error

Line: 1 Column: 1

              from ctypes import *
import os
import shutil
import subprocess
import sys
import unittest
import test.support
from test.support import import_helper
from test.support import os_helper

            

Reported by Pylint.

Unused import Structure from wildcard import
Error

Line: 1 Column: 1

              from ctypes import *
import os
import shutil
import subprocess
import sys
import unittest
import test.support
from test.support import import_helper
from test.support import os_helper

            

Reported by Pylint.

Unused import Union from wildcard import
Error

Line: 1 Column: 1

              from ctypes import *
import os
import shutil
import subprocess
import sys
import unittest
import test.support
from test.support import import_helper
from test.support import os_helper

            

Reported by Pylint.

Unused import c_uint64 from wildcard import
Error

Line: 1 Column: 1

              from ctypes import *
import os
import shutil
import subprocess
import sys
import unittest
import test.support
from test.support import import_helper
from test.support import os_helper

            

Reported by Pylint.

Lib/unittest/test/test_program.py
108 issues
Attribute 'wasRun' defined outside __init__
Error

Line: 19 Column: 9

                      tests = [self]
        expectedPath = os.path.abspath(os.path.dirname(unittest.test.__file__))

        self.wasRun = False
        def _find_tests(start_dir, pattern):
            self.wasRun = True
            self.assertEqual(start_dir, expectedPath)
            return tests
        loader._find_tests = _find_tests

            

Reported by Pylint.

Unused argument 'pattern'
Error

Line: 20 Column: 36

                      expectedPath = os.path.abspath(os.path.dirname(unittest.test.__file__))

        self.wasRun = False
        def _find_tests(start_dir, pattern):
            self.wasRun = True
            self.assertEqual(start_dir, expectedPath)
            return tests
        loader._find_tests = _find_tests
        suite = loader.discover('unittest.test')

            

Reported by Pylint.

Attribute 'wasRun' defined outside __init__
Error

Line: 21 Column: 13

              
        self.wasRun = False
        def _find_tests(start_dir, pattern):
            self.wasRun = True
            self.assertEqual(start_dir, expectedPath)
            return tests
        loader._find_tests = _find_tests
        suite = loader.discover('unittest.test')
        self.assertTrue(self.wasRun)

            

Reported by Pylint.

Access to a protected member _find_tests of a client class
Error

Line: 24 Column: 9

                          self.wasRun = True
            self.assertEqual(start_dir, expectedPath)
            return tests
        loader._find_tests = _find_tests
        suite = loader.discover('unittest.test')
        self.assertTrue(self.wasRun)
        self.assertEqual(suite._tests, tests)

    # Horrible white box test

            

Reported by Pylint.

Access to a protected member _tests of a client class
Error

Line: 27 Column: 26

                      loader._find_tests = _find_tests
        suite = loader.discover('unittest.test')
        self.assertTrue(self.wasRun)
        self.assertEqual(suite._tests, tests)

    # Horrible white box test
    def testNoExit(self):
        result = object()
        test = object()

            

Reported by Pylint.

Redefining name 'FakeRunner' from outer scope (line 149)
Error

Line: 34 Column: 9

                      result = object()
        test = object()

        class FakeRunner(object):
            def run(self, test):
                self.test = test
                return result

        runner = FakeRunner()

            

Reported by Pylint.

Attribute 'test' defined outside __init__
Error

Line: 36 Column: 17

              
        class FakeRunner(object):
            def run(self, test):
                self.test = test
                return result

        runner = FakeRunner()

        oldParseArgs = unittest.TestProgram.parseArgs

            

Reported by Pylint.

Parameters differ from overridden 'loadTestsFromModule' method
Error

Line: 66 Column: 9

              
    class FooBarLoader(unittest.TestLoader):
        """Test loader that returns a suite containing FooBar."""
        def loadTestsFromModule(self, module):
            return self.suiteClass(
                [self.loadTestsFromTestCase(Test_TestProgram.FooBar)])

        def loadTestsFromNames(self, names, module):
            return self.suiteClass(

            

Reported by Pylint.

Signature differs from overridden 'loadTestsFromNames' method
Error

Line: 70 Column: 9

                          return self.suiteClass(
                [self.loadTestsFromTestCase(Test_TestProgram.FooBar)])

        def loadTestsFromNames(self, names, module):
            return self.suiteClass(
                [self.loadTestsFromTestCase(Test_TestProgram.FooBar)])

    def test_defaultTest_with_string(self):
        class FakeRunner(object):

            

Reported by Pylint.

Redefining name 'FakeRunner' from outer scope (line 149)
Error

Line: 75 Column: 9

                              [self.loadTestsFromTestCase(Test_TestProgram.FooBar)])

    def test_defaultTest_with_string(self):
        class FakeRunner(object):
            def run(self, test):
                self.test = test
                return True

        old_argv = sys.argv

            

Reported by Pylint.

Lib/ctypes/test/test_cfuncs.py
108 issues
Unused import pythonapi from wildcard import
Error

Line: 5 Column: 1

              # Byte order related?

import unittest
from ctypes import *
from ctypes.test import need_symbol

import _ctypes_test

class CFunctions(unittest.TestCase):

            

Reported by Pylint.

Unused import c_uint32 from wildcard import
Error

Line: 5 Column: 1

              # Byte order related?

import unittest
from ctypes import *
from ctypes.test import need_symbol

import _ctypes_test

class CFunctions(unittest.TestCase):

            

Reported by Pylint.

Unused import c_uint16 from wildcard import
Error

Line: 5 Column: 1

              # Byte order related?

import unittest
from ctypes import *
from ctypes.test import need_symbol

import _ctypes_test

class CFunctions(unittest.TestCase):

            

Reported by Pylint.

Unused import c_int64 from wildcard import
Error

Line: 5 Column: 1

              # Byte order related?

import unittest
from ctypes import *
from ctypes.test import need_symbol

import _ctypes_test

class CFunctions(unittest.TestCase):

            

Reported by Pylint.

Unused import c_int32 from wildcard import
Error

Line: 5 Column: 1

              # Byte order related?

import unittest
from ctypes import *
from ctypes.test import need_symbol

import _ctypes_test

class CFunctions(unittest.TestCase):

            

Reported by Pylint.

Unused import c_int16 from wildcard import
Error

Line: 5 Column: 1

              # Byte order related?

import unittest
from ctypes import *
from ctypes.test import need_symbol

import _ctypes_test

class CFunctions(unittest.TestCase):

            

Reported by Pylint.

Unused import kind from wildcard import
Error

Line: 5 Column: 1

              # Byte order related?

import unittest
from ctypes import *
from ctypes.test import need_symbol

import _ctypes_test

class CFunctions(unittest.TestCase):

            

Reported by Pylint.

Unused import c_uint8 from wildcard import
Error

Line: 5 Column: 1

              # Byte order related?

import unittest
from ctypes import *
from ctypes.test import need_symbol

import _ctypes_test

class CFunctions(unittest.TestCase):

            

Reported by Pylint.

Unused import c_int8 from wildcard import
Error

Line: 5 Column: 1

              # Byte order related?

import unittest
from ctypes import *
from ctypes.test import need_symbol

import _ctypes_test

class CFunctions(unittest.TestCase):

            

Reported by Pylint.

Unused import DllCanUnloadNow from wildcard import
Error

Line: 5 Column: 1

              # Byte order related?

import unittest
from ctypes import *
from ctypes.test import need_symbol

import _ctypes_test

class CFunctions(unittest.TestCase):

            

Reported by Pylint.

Lib/test/test_locale.py
108 issues
Instance of 'BaseLocalizedTest' has no 'locale_type' member
Error

Line: 46 Column: 38

                          locale.setlocale(locale.LC_NUMERIC, oldlocale)

    def setUp(self):
        oldlocale = locale.setlocale(self.locale_type)
        self.addCleanup(locale.setlocale, self.locale_type, oldlocale)
        locale.setlocale(self.locale_type, self.enUS_locale)
        if verbose:
            print("testing with %r..." % self.enUS_locale, end=' ', flush=True)


            

Reported by Pylint.

Instance of 'BaseLocalizedTest' has no 'locale_type' member
Error

Line: 47 Column: 43

              
    def setUp(self):
        oldlocale = locale.setlocale(self.locale_type)
        self.addCleanup(locale.setlocale, self.locale_type, oldlocale)
        locale.setlocale(self.locale_type, self.enUS_locale)
        if verbose:
            print("testing with %r..." % self.enUS_locale, end=' ', flush=True)



            

Reported by Pylint.

Instance of 'BaseLocalizedTest' has no 'locale_type' member
Error

Line: 48 Column: 26

                  def setUp(self):
        oldlocale = locale.setlocale(self.locale_type)
        self.addCleanup(locale.setlocale, self.locale_type, oldlocale)
        locale.setlocale(self.locale_type, self.enUS_locale)
        if verbose:
            print("testing with %r..." % self.enUS_locale, end=' ', flush=True)


class BaseCookedTest(unittest.TestCase):

            

Reported by Pylint.

Instance of 'BaseCookedTest' has no 'cooked_values' member
Error

Line: 59 Column: 39

                  #

    def setUp(self):
        locale._override_localeconv = self.cooked_values

    def tearDown(self):
        locale._override_localeconv = {}

class CCookedTest(BaseCookedTest):

            

Reported by Pylint.

Instance of 'BaseFormattingTest' has no 'assertEqual' member
Error

Line: 145 Column: 9

                  #

    def _test_formatfunc(self, format, value, out, func, **format_opts):
        self.assertEqual(
            func(format, value, **format_opts), out)

    def _test_format(self, format, value, out, **format_opts):
        with check_warnings(('', DeprecationWarning)):
            self._test_formatfunc(format, value, out,

            

Reported by Pylint.

Instance of 'BaseFormattingTest' has no 'assertEqual' member
Error

Line: 158 Column: 9

                          func=locale.format_string, **format_opts)

    def _test_currency(self, value, out, **format_opts):
        self.assertEqual(locale.currency(value, **format_opts), out)


class EnUSNumberFormatting(BaseFormattingTest):
    # XXX there is a grouping + padding bug when the thousands separator
    # is empty but the grouping array contains values (e.g. Solaris 10)

            

Reported by Pylint.

Instance of 'EnUSNumberFormatting' has no 'assertWarns' member
Error

Line: 205 Column: 14

                      self._test_format("%-10.f", 4200, grouping=0, out='4200'.ljust(10))

    def test_format_deprecation(self):
        with self.assertWarns(DeprecationWarning):
            locale.format("%-10.f", 4200, grouping=True)

    def test_complex_formatting(self):
        # Spaces in formatting string
        self._test_format_string("One million is %i", 1000000, grouping=1,

            

Reported by Pylint.

Argument 'builtins.tuple' does not match format type 'a'
Error

Line: 567 Column: 19

                          self.skipTest('test needs Turkish locale')
        loc = locale.getlocale(locale.LC_CTYPE)
        if verbose:
            print('testing with %a' % (loc,), end=' ', flush=True)
        try:
            locale.setlocale(locale.LC_CTYPE, loc)
        except locale.Error as exc:
            # bpo-37945: setlocale(LC_CTYPE) fails with getlocale(LC_CTYPE)
            # and the tr_TR locale on Windows. getlocale() builds a locale

            

Reported by Pylint.

Access to a protected member _override_localeconv of a client class
Error

Line: 59 Column: 9

                  #

    def setUp(self):
        locale._override_localeconv = self.cooked_values

    def tearDown(self):
        locale._override_localeconv = {}

class CCookedTest(BaseCookedTest):

            

Reported by Pylint.

Access to a protected member _override_localeconv of a client class
Error

Line: 62 Column: 9

                      locale._override_localeconv = self.cooked_values

    def tearDown(self):
        locale._override_localeconv = {}

class CCookedTest(BaseCookedTest):
    # A cooked "C" locale

    cooked_values = {

            

Reported by Pylint.

Lib/test/test_email/test_defect_handling.py
108 issues
Instance of 'TestDefectsBase' has no '_str_msg' member
Error

Line: 57 Column: 19

                          """)
        # XXX better would be to actually detect the duplicate.
        with self._raise_point(errors.StartBoundaryNotFoundDefect):
            msg = self._str_msg(source)
        if self.raise_expected: return
        inner = msg.get_payload(0)
        self.assertTrue(hasattr(inner, 'defects'))
        self.assertEqual(len(self.get_defects(inner)), 1)
        self.assertIsInstance(self.get_defects(inner)[0],

            

Reported by Pylint.

Instance of 'TestDefectsBase' has no 'assertTrue' member
Error

Line: 60 Column: 9

                          msg = self._str_msg(source)
        if self.raise_expected: return
        inner = msg.get_payload(0)
        self.assertTrue(hasattr(inner, 'defects'))
        self.assertEqual(len(self.get_defects(inner)), 1)
        self.assertIsInstance(self.get_defects(inner)[0],
                              errors.StartBoundaryNotFoundDefect)

    def test_multipart_no_boundary(self):

            

Reported by Pylint.

Instance of 'TestDefectsBase' has no 'assertEqual' member
Error

Line: 61 Column: 9

                      if self.raise_expected: return
        inner = msg.get_payload(0)
        self.assertTrue(hasattr(inner, 'defects'))
        self.assertEqual(len(self.get_defects(inner)), 1)
        self.assertIsInstance(self.get_defects(inner)[0],
                              errors.StartBoundaryNotFoundDefect)

    def test_multipart_no_boundary(self):
        source = textwrap.dedent("""\

            

Reported by Pylint.

Instance of 'TestDefectsBase' has no 'get_defects' member
Error

Line: 61 Column: 30

                      if self.raise_expected: return
        inner = msg.get_payload(0)
        self.assertTrue(hasattr(inner, 'defects'))
        self.assertEqual(len(self.get_defects(inner)), 1)
        self.assertIsInstance(self.get_defects(inner)[0],
                              errors.StartBoundaryNotFoundDefect)

    def test_multipart_no_boundary(self):
        source = textwrap.dedent("""\

            

Reported by Pylint.

Instance of 'TestDefectsBase' has no 'get_defects' member
Error

Line: 62 Column: 31

                      inner = msg.get_payload(0)
        self.assertTrue(hasattr(inner, 'defects'))
        self.assertEqual(len(self.get_defects(inner)), 1)
        self.assertIsInstance(self.get_defects(inner)[0],
                              errors.StartBoundaryNotFoundDefect)

    def test_multipart_no_boundary(self):
        source = textwrap.dedent("""\
            Date: Fri, 6 Apr 2001 09:23:06 -0800 (GMT-0800)

            

Reported by Pylint.

Instance of 'TestDefectsBase' has no 'assertIsInstance' member
Error

Line: 62 Column: 9

                      inner = msg.get_payload(0)
        self.assertTrue(hasattr(inner, 'defects'))
        self.assertEqual(len(self.get_defects(inner)), 1)
        self.assertIsInstance(self.get_defects(inner)[0],
                              errors.StartBoundaryNotFoundDefect)

    def test_multipart_no_boundary(self):
        source = textwrap.dedent("""\
            Date: Fri, 6 Apr 2001 09:23:06 -0800 (GMT-0800)

            

Reported by Pylint.

Instance of 'TestDefectsBase' has no '_str_msg' member
Error

Line: 85 Column: 19

                          --JAB03225.986577786/zinfandel.lacita.com--
            """)
        with self._raise_point(errors.NoBoundaryInMultipartDefect):
            msg = self._str_msg(source)
        if self.raise_expected: return
        self.assertIsInstance(msg.get_payload(), str)
        self.assertEqual(len(self.get_defects(msg)), 2)
        self.assertIsInstance(self.get_defects(msg)[0],
                              errors.NoBoundaryInMultipartDefect)

            

Reported by Pylint.

Instance of 'TestDefectsBase' has no 'assertIsInstance' member
Error

Line: 87 Column: 9

                      with self._raise_point(errors.NoBoundaryInMultipartDefect):
            msg = self._str_msg(source)
        if self.raise_expected: return
        self.assertIsInstance(msg.get_payload(), str)
        self.assertEqual(len(self.get_defects(msg)), 2)
        self.assertIsInstance(self.get_defects(msg)[0],
                              errors.NoBoundaryInMultipartDefect)
        self.assertIsInstance(self.get_defects(msg)[1],
                              errors.MultipartInvariantViolationDefect)

            

Reported by Pylint.

Instance of 'TestDefectsBase' has no 'assertEqual' member
Error

Line: 88 Column: 9

                          msg = self._str_msg(source)
        if self.raise_expected: return
        self.assertIsInstance(msg.get_payload(), str)
        self.assertEqual(len(self.get_defects(msg)), 2)
        self.assertIsInstance(self.get_defects(msg)[0],
                              errors.NoBoundaryInMultipartDefect)
        self.assertIsInstance(self.get_defects(msg)[1],
                              errors.MultipartInvariantViolationDefect)


            

Reported by Pylint.

Instance of 'TestDefectsBase' has no 'get_defects' member
Error

Line: 88 Column: 30

                          msg = self._str_msg(source)
        if self.raise_expected: return
        self.assertIsInstance(msg.get_payload(), str)
        self.assertEqual(len(self.get_defects(msg)), 2)
        self.assertIsInstance(self.get_defects(msg)[0],
                              errors.NoBoundaryInMultipartDefect)
        self.assertIsInstance(self.get_defects(msg)[1],
                              errors.MultipartInvariantViolationDefect)


            

Reported by Pylint.

Tools/ccbench/ccbench.py
108 issues
Undefined variable 'bz2'
Error

Line: 138 Column: 4

              # For whatever reasons, zlib gives irregular results, so we prefer bz2 or
# hashlib if available.
# (NOTE: hashlib releases the GIL from 2.7 and 3.1 onwards)
if bz2 is not None:
    throughput_tasks.append(task_compress_bz2)
elif hashlib is not None:
    throughput_tasks.append(task_hashing)
else:
    throughput_tasks.append(task_compress_zlib)

            

Reported by Pylint.

Undefined variable 'hashlib'
Error

Line: 140 Column: 6

              # (NOTE: hashlib releases the GIL from 2.7 and 3.1 onwards)
if bz2 is not None:
    throughput_tasks.append(task_compress_bz2)
elif hashlib is not None:
    throughput_tasks.append(task_hashing)
else:
    throughput_tasks.append(task_compress_zlib)

latency_tasks = throughput_tasks

            

Reported by Pylint.

String statement has no effect
Error

Line: 6 Column: 1

              from __future__ import division
from __future__ import print_function

"""
ccbench, a Python concurrency benchmark.
"""

import time
import os

            

Reported by Pylint.

Uses of a deprecated module 'optparse'
Error

Line: 17 Column: 1

              import threading
import subprocess
import socket
from optparse import OptionParser, SUPPRESS_HELP
import platform

# Compatibility
try:
    xrange

            

Reported by Pylint.

Redefining built-in 'map'
Error

Line: 27 Column: 5

                  xrange = range

try:
    map = itertools.imap
except AttributeError:
    pass


THROUGHPUT_DURATION = 2.0

            

Reported by Pylint.

XXX this task gives horrendous latency results.
Error

Line: 81 Column: 3

              
def task_regex():
    """regular expression (C)"""
    # XXX this task gives horrendous latency results.
    import re
    # Taken from the `inspect` module
    pat = re.compile(r'^(\s*def\s)|(.*(?<!\w)lambda(:|\s))|^(\s*@)', re.MULTILINE)
    with open(__file__, "r") as f:
        arg = f.read(2000)

            

Reported by Pylint.

Use of insecure MD2, MD4, MD5, or SHA1 hash function.
Security blacklist

Line: 124
Suggestion: https://bandit.readthedocs.io/en/latest/blacklists/blacklist_calls.html#b303-md5

                      arg = f.read(5000) * 30

    def compute(s):
        hashlib.sha1(s).digest()
    return compute, (arg, )


throughput_tasks = [task_pidigits, task_regex]
for mod in 'bz2', 'hashlib':

            

Reported by Bandit.

Unused variable 'i'
Error

Line: 164 Column: 17

                      _args = self.args
        t1 = start_time
        while True:
            for i in range(step):
                _func(*_args)
            t2 = _time()
            # If another thread terminated, the current measurement is invalid
            # => return the previous one.
            if end_event:

            

Reported by Pylint.

Unused variable 'i'
Error

Line: 221 Column: 9

                                          end_event, do_yield=True))

    threads = []
    for i in range(nthreads):
        threads.append(threading.Thread(target=run))
    for t in threads:
        t.daemon = True
        t.start()
    # We don't want measurements to include thread startup overhead,

            

Reported by Pylint.

Unused variable 'i'
Error

Line: 281 Column: 13

                      _ping()
        # We give the parent a bit of time to notice.
        _sleep(1.0)
        for i in range(nb_pings):
            _sleep(interval)
            _ping()
        _sendto(sock, LAT_END + "\n", addr)
    finally:
        sock.close()

            

Reported by Pylint.

Lib/test/test_keywordonlyarg.py
108 issues
Too many positional arguments for function call
Error

Line: 65 Column: 13

                      def f(a, b=None, *, c=None):
            pass
        with self.assertRaises(TypeError) as exc:
            f(1, 2, 3)
        expected = (f"{f.__qualname__}() takes from 1 to 2 "
                    "positional arguments but 3 were given")
        self.assertEqual(str(exc.exception), expected)

    def testSyntaxErrorForFunctionCall(self):

            

Reported by Pylint.

Unexpected keyword argument 'non_existing_arg' in function call
Error

Line: 79 Column: 13

                      self.assertRaises(TypeError, keywordonly_nodefaults_sum, ())
        self.assertRaises(TypeError, Foo, ())
        try:
            keywordonly_sum(k2=100, non_existing_arg=200)
            self.fail("should raise TypeError")
        except TypeError:
            pass
        try:
            keywordonly_nodefaults_sum(k2=2)

            

Reported by Pylint.

Missing mandatory keyword argument 'k1' in function call
Error

Line: 84 Column: 13

                      except TypeError:
            pass
        try:
            keywordonly_nodefaults_sum(k2=2)
            self.fail("should raise TypeError")
        except TypeError:
            pass

    def testFunctionCall(self):

            

Reported by Pylint.

Undefined variable 'b'
Error

Line: 169 Column: 26

                      # See issue 16967
        a = 42
        with self.assertRaises(NameError) as err:
            def f(v=a, x=b, *, y=c, z=d):
                pass
        self.assertEqual(str(err.exception), "name 'b' is not defined")
        with self.assertRaises(NameError) as err:
            f = lambda v=a, x=b, *, y=c, z=d: None
        self.assertEqual(str(err.exception), "name 'b' is not defined")

            

Reported by Pylint.

Undefined variable 'd'
Error

Line: 169 Column: 39

                      # See issue 16967
        a = 42
        with self.assertRaises(NameError) as err:
            def f(v=a, x=b, *, y=c, z=d):
                pass
        self.assertEqual(str(err.exception), "name 'b' is not defined")
        with self.assertRaises(NameError) as err:
            f = lambda v=a, x=b, *, y=c, z=d: None
        self.assertEqual(str(err.exception), "name 'b' is not defined")

            

Reported by Pylint.

Undefined variable 'c'
Error

Line: 169 Column: 34

                      # See issue 16967
        a = 42
        with self.assertRaises(NameError) as err:
            def f(v=a, x=b, *, y=c, z=d):
                pass
        self.assertEqual(str(err.exception), "name 'b' is not defined")
        with self.assertRaises(NameError) as err:
            f = lambda v=a, x=b, *, y=c, z=d: None
        self.assertEqual(str(err.exception), "name 'b' is not defined")

            

Reported by Pylint.

Undefined variable 'c'
Error

Line: 173 Column: 39

                              pass
        self.assertEqual(str(err.exception), "name 'b' is not defined")
        with self.assertRaises(NameError) as err:
            f = lambda v=a, x=b, *, y=c, z=d: None
        self.assertEqual(str(err.exception), "name 'b' is not defined")


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

            

Reported by Pylint.

Undefined variable 'b'
Error

Line: 173 Column: 31

                              pass
        self.assertEqual(str(err.exception), "name 'b' is not defined")
        with self.assertRaises(NameError) as err:
            f = lambda v=a, x=b, *, y=c, z=d: None
        self.assertEqual(str(err.exception), "name 'b' is not defined")


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

            

Reported by Pylint.

Undefined variable 'd'
Error

Line: 173 Column: 44

                              pass
        self.assertEqual(str(err.exception), "name 'b' is not defined")
        with self.assertRaises(NameError) as err:
            f = lambda v=a, x=b, *, y=c, z=d: None
        self.assertEqual(str(err.exception), "name 'b' is not defined")


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

            

Reported by Pylint.

Keyword argument before variable positional arguments list in the definition of mixedargs_sum function
Error

Line: 16 Column: 1

                  return k1 + k2
def keywordonly_and_kwarg_sum(*, k1, k2, **kwarg):
    return k1 + k2 + sum(kwarg.values())
def mixedargs_sum(a, b=0, *arg, k1, k2=0):
    return a + b + k1 + k2 + sum(arg)
def mixedargs_sum2(a, b=0, *arg, k1, k2=0, **kwargs):
    return a + b + k1 + k2 + sum(arg) + sum(kwargs.values())

def sortnum(*nums, reverse=False):

            

Reported by Pylint.

Lib/test/test_sort.py
108 issues
function already defined line 155
Error

Line: 161 Column: 13

                              return (x > y) - (x < y)
            L = [1,2]
            self.assertRaises(ValueError, L.sort, key=cmp_to_key(mutating_cmp))
            def mutating_cmp(x, y):
                L.append(3)
                del L[:]
                return (x > y) - (x < y)
            self.assertRaises(ValueError, L.sort, key=cmp_to_key(mutating_cmp))
            memorywaster = [memorywaster]

            

Reported by Pylint.

Using the global statement
Error

Line: 11 Column: 5

              

def check(tag, expected, raw, compare=None):
    global nerrors

    if verbose:
        print("    checking", tag)

    orig = raw[:]   # save input in case of error

            

Reported by Pylint.

Unused variable 'i'
Error

Line: 154 Column: 13

                  def test_undetected_mutation(self):
        # Python 2.4a1 did not always detect mutation
        memorywaster = []
        for i in range(20):
            def mutating_cmp(x, y):
                L.append(3)
                L.pop()
                return (x > y) - (x < y)
            L = [1,2]

            

Reported by Pylint.

Cell variable L defined in loop
Error

Line: 156 Column: 17

                      memorywaster = []
        for i in range(20):
            def mutating_cmp(x, y):
                L.append(3)
                L.pop()
                return (x > y) - (x < y)
            L = [1,2]
            self.assertRaises(ValueError, L.sort, key=cmp_to_key(mutating_cmp))
            def mutating_cmp(x, y):

            

Reported by Pylint.

Cell variable L defined in loop
Error

Line: 157 Column: 17

                      for i in range(20):
            def mutating_cmp(x, y):
                L.append(3)
                L.pop()
                return (x > y) - (x < y)
            L = [1,2]
            self.assertRaises(ValueError, L.sort, key=cmp_to_key(mutating_cmp))
            def mutating_cmp(x, y):
                L.append(3)

            

Reported by Pylint.

Cell variable L defined in loop
Error

Line: 162 Column: 17

                          L = [1,2]
            self.assertRaises(ValueError, L.sort, key=cmp_to_key(mutating_cmp))
            def mutating_cmp(x, y):
                L.append(3)
                del L[:]
                return (x > y) - (x < y)
            self.assertRaises(ValueError, L.sort, key=cmp_to_key(mutating_cmp))
            memorywaster = [memorywaster]


            

Reported by Pylint.

Cell variable L defined in loop
Error

Line: 163 Column: 21

                          self.assertRaises(ValueError, L.sort, key=cmp_to_key(mutating_cmp))
            def mutating_cmp(x, y):
                L.append(3)
                del L[:]
                return (x > y) - (x < y)
            self.assertRaises(ValueError, L.sort, key=cmp_to_key(mutating_cmp))
            memorywaster = [memorywaster]

#==============================================================================

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from test import support
import random
import unittest
from functools import cmp_to_key

verbose = support.verbose
nerrors = 0



            

Reported by Pylint.

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

Line: 6 Column: 1

              import unittest
from functools import cmp_to_key

verbose = support.verbose
nerrors = 0


def check(tag, expected, raw, compare=None):
    global nerrors

            

Reported by Pylint.

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

Line: 7 Column: 1

              from functools import cmp_to_key

verbose = support.verbose
nerrors = 0


def check(tag, expected, raw, compare=None):
    global nerrors


            

Reported by Pylint.

Lib/ctypes/test/test_pickling.py
107 issues
Instance of 'PickleTest' has no 'proto' member
Error

Line: 19 Column: 35

              
class PickleTest:
    def dumps(self, item):
        return pickle.dumps(item, self.proto)

    def loads(self, item):
        return pickle.loads(item)

    def test_simple(self):

            

Reported by Pylint.

Instance of 'PickleTest' has no 'assertEqual' member
Error

Line: 30 Column: 13

                          c_double(3.14),
            ]:
            dst = self.loads(self.dumps(src))
            self.assertEqual(src.__dict__, dst.__dict__)
            self.assertEqual(memoryview(src).tobytes(),
                                 memoryview(dst).tobytes())

    def test_struct(self):
        X.init_called = 0

            

Reported by Pylint.

Instance of 'PickleTest' has no 'assertEqual' member
Error

Line: 31 Column: 13

                          ]:
            dst = self.loads(self.dumps(src))
            self.assertEqual(src.__dict__, dst.__dict__)
            self.assertEqual(memoryview(src).tobytes(),
                                 memoryview(dst).tobytes())

    def test_struct(self):
        X.init_called = 0


            

Reported by Pylint.

Instance of 'PickleTest' has no 'assertEqual' member
Error

Line: 39 Column: 9

              
        x = X()
        x.a = 42
        self.assertEqual(X.init_called, 1)

        y = self.loads(self.dumps(x))

        # loads must NOT call __init__
        self.assertEqual(X.init_called, 1)

            

Reported by Pylint.

Instance of 'PickleTest' has no 'assertEqual' member
Error

Line: 44 Column: 9

                      y = self.loads(self.dumps(x))

        # loads must NOT call __init__
        self.assertEqual(X.init_called, 1)

        # ctypes instances are identical when the instance __dict__
        # and the memory buffer are identical
        self.assertEqual(y.__dict__, x.__dict__)
        self.assertEqual(memoryview(y).tobytes(),

            

Reported by Pylint.

Instance of 'PickleTest' has no 'assertEqual' member
Error

Line: 48 Column: 9

              
        # ctypes instances are identical when the instance __dict__
        # and the memory buffer are identical
        self.assertEqual(y.__dict__, x.__dict__)
        self.assertEqual(memoryview(y).tobytes(),
                             memoryview(x).tobytes())

    def test_unpickable(self):
        # ctypes objects that are pointers or contain pointers are

            

Reported by Pylint.

Instance of 'PickleTest' has no 'assertEqual' member
Error

Line: 49 Column: 9

                      # ctypes instances are identical when the instance __dict__
        # and the memory buffer are identical
        self.assertEqual(y.__dict__, x.__dict__)
        self.assertEqual(memoryview(y).tobytes(),
                             memoryview(x).tobytes())

    def test_unpickable(self):
        # ctypes objects that are pointers or contain pointers are
        # unpickable.

            

Reported by Pylint.

Instance of 'PickleTest' has no 'assertRaises' member
Error

Line: 55 Column: 9

                  def test_unpickable(self):
        # ctypes objects that are pointers or contain pointers are
        # unpickable.
        self.assertRaises(ValueError, lambda: self.dumps(Y()))

        prototype = CFUNCTYPE(c_int)

        for item in [
            c_char_p(),

            

Reported by Pylint.

Instance of 'PickleTest' has no 'assertRaises' member
Error

Line: 67 Column: 13

                          dll._testfunc_p_p,
            prototype(lambda: 42),
            ]:
            self.assertRaises(ValueError, lambda: self.dumps(item))

    def test_wchar(self):
        self.dumps(c_char(b"x"))
        # Issue 5049
        self.dumps(c_wchar("x"))

            

Reported by Pylint.

Unused import c_ushort from wildcard import
Error

Line: 3 Column: 1

              import unittest
import pickle
from ctypes import *
import _ctypes_test
dll = CDLL(_ctypes_test.__file__)

class X(Structure):
    _fields_ = [("a", c_int), ("b", c_double)]
    init_called = 0

            

Reported by Pylint.

Tools/peg_generator/pegen/c_generator.py
107 issues
Using an f-string that does not have any interpolated variables
Error

Line: 163 Column: 26

                              )
            return FunctionCall(
                assigned_variable=f"{name.lower()}_var",
                function=f"_PyPegen_expect_token",
                arguments=["p", name],
                nodetype=NodeTypes.GENERIC_TOKEN,
                return_type="Token *",
                comment=f"token='{name}'",
            )

            

Reported by Pylint.

Redefining built-in 'type'
Error

Line: 170 Column: 9

                              comment=f"token='{name}'",
            )

        type = None
        rule = self.gen.all_rules.get(name.lower())
        if rule is not None:
            type = "asdl_seq *" if rule.is_loop() or rule.is_gather() else rule.type

        return FunctionCall(

            

Reported by Pylint.

Redefining built-in 'type'
Error

Line: 192 Column: 13

                              return self.soft_keyword_helper(node.value)
        else:
            assert val in self.exact_tokens, f"{node.value} is not a known literal"
            type = self.exact_tokens[val]
            return FunctionCall(
                assigned_variable="_literal",
                function=f"_PyPegen_expect_token",
                arguments=["p", type],
                nodetype=NodeTypes.GENERIC_TOKEN,

            

Reported by Pylint.

Using an f-string that does not have any interpolated variables
Error

Line: 195 Column: 26

                          type = self.exact_tokens[val]
            return FunctionCall(
                assigned_variable="_literal",
                function=f"_PyPegen_expect_token",
                arguments=["p", type],
                nodetype=NodeTypes.GENERIC_TOKEN,
                return_type="Token *",
                comment=f"token='{val}'",
            )

            

Reported by Pylint.

Using an f-string that does not have any interpolated variables
Error

Line: 237 Column: 26

                      call = self.generate_call(node.node)
        if call.nodetype == NodeTypes.NAME_TOKEN:
            return FunctionCall(
                function=f"_PyPegen_lookahead_with_name",
                arguments=[positive, call.function, *call.arguments],
                return_type="int",
            )
        elif call.nodetype == NodeTypes.SOFT_KEYWORD:
            return FunctionCall(

            

Reported by Pylint.

Using an f-string that does not have any interpolated variables
Error

Line: 243 Column: 26

                          )
        elif call.nodetype == NodeTypes.SOFT_KEYWORD:
            return FunctionCall(
                function=f"_PyPegen_lookahead_with_string",
                arguments=[positive, call.function, *call.arguments],
                return_type="int",
            )
        elif call.nodetype in {NodeTypes.GENERIC_TOKEN, NodeTypes.KEYWORD}:
            return FunctionCall(

            

Reported by Pylint.

Using an f-string that does not have any interpolated variables
Error

Line: 249 Column: 26

                          )
        elif call.nodetype in {NodeTypes.GENERIC_TOKEN, NodeTypes.KEYWORD}:
            return FunctionCall(
                function=f"_PyPegen_lookahead_with_int",
                arguments=[positive, call.function, *call.arguments],
                return_type="int",
                comment=f"token={node.node}",
            )
        else:

            

Reported by Pylint.

Using an f-string that does not have any interpolated variables
Error

Line: 256 Column: 26

                          )
        else:
            return FunctionCall(
                function=f"_PyPegen_lookahead",
                arguments=[positive, call.function, *call.arguments],
                return_type="int",
            )

    def visit_PositiveLookahead(self, node: PositiveLookahead) -> FunctionCall:

            

Reported by Pylint.

Redefining built-in 'type'
Error

Line: 273 Column: 13

                          assert isinstance(node.node, Leaf)
            val = ast.literal_eval(node.node.value)
            assert val in self.exact_tokens, f"{node.node.value} is not a known literal"
            type = self.exact_tokens[val]
            return FunctionCall(
                assigned_variable="_literal",
                function=f"_PyPegen_expect_forced_token",
                arguments=["p", type, f'"{val}"'],
                nodetype=NodeTypes.GENERIC_TOKEN,

            

Reported by Pylint.

Using an f-string that does not have any interpolated variables
Error

Line: 276 Column: 26

                          type = self.exact_tokens[val]
            return FunctionCall(
                assigned_variable="_literal",
                function=f"_PyPegen_expect_forced_token",
                arguments=["p", type, f'"{val}"'],
                nodetype=NodeTypes.GENERIC_TOKEN,
                return_type="Token *",
                comment=f"forced_token='{val}'",
            )

            

Reported by Pylint.