The following issues were found
Tools/unicode/genwincodec.py
8 issues
Line: 45
Column: 5
def genwincodec(codepage):
import platform
map = genwinmap(codepage)
encodingname = 'cp%d' % codepage
code = codegen("", map, encodingname)
# Replace first lines with our own docstring
code = '''\
"""Python Character Mapping Codec %s generated on Windows:
Reported by Pylint.
Line: 9
Column: 1
import ctypes
from ctypes import wintypes
from gencodec import codegen
import unicodedata
def genwinmap(codepage):
MultiByteToWideChar = ctypes.windll.kernel32.MultiByteToWideChar
MultiByteToWideChar.argtypes = [wintypes.UINT, wintypes.DWORD,
wintypes.LPCSTR, ctypes.c_int,
Reported by Pylint.
Line: 11
Column: 1
from gencodec import codegen
import unicodedata
def genwinmap(codepage):
MultiByteToWideChar = ctypes.windll.kernel32.MultiByteToWideChar
MultiByteToWideChar.argtypes = [wintypes.UINT, wintypes.DWORD,
wintypes.LPCSTR, ctypes.c_int,
wintypes.LPWSTR, ctypes.c_int]
MultiByteToWideChar.restype = ctypes.c_int
Reported by Pylint.
Line: 12
Column: 5
import unicodedata
def genwinmap(codepage):
MultiByteToWideChar = ctypes.windll.kernel32.MultiByteToWideChar
MultiByteToWideChar.argtypes = [wintypes.UINT, wintypes.DWORD,
wintypes.LPCSTR, ctypes.c_int,
wintypes.LPWSTR, ctypes.c_int]
MultiByteToWideChar.restype = ctypes.c_int
Reported by Pylint.
Line: 29
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
codepage, 0,
bytes([i]), 1,
buf, 2)
assert ret == 1, "invalid code page"
assert buf[1] == '\x00'
try:
name = unicodedata.name(buf[0])
except ValueError:
try:
Reported by Bandit.
Line: 30
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
bytes([i]), 1,
buf, 2)
assert ret == 1, "invalid code page"
assert buf[1] == '\x00'
try:
name = unicodedata.name(buf[0])
except ValueError:
try:
name = enc2uni[i][1]
Reported by Bandit.
Line: 43
Column: 1
return enc2uni
def genwincodec(codepage):
import platform
map = genwinmap(codepage)
encodingname = 'cp%d' % codepage
code = codegen("", map, encodingname)
# Replace first lines with our own docstring
Reported by Pylint.
Line: 44
Column: 5
return enc2uni
def genwincodec(codepage):
import platform
map = genwinmap(codepage)
encodingname = 'cp%d' % codepage
code = codegen("", map, encodingname)
# Replace first lines with our own docstring
code = '''\
Reported by Pylint.
Tools/peg_generator/scripts/ast_timings.py
8 issues
Line: 15
Column: 13
try:
with open(filename) as file:
source = file.read()
tree = ast.parse(source, filename)
except Exception as err:
print(f"{filename}: {err.__class__.__name__}: {err}", file=sys.stderr)
tok = None
t1 = time.time()
dt = t1 - t0
Reported by Pylint.
Line: 16
Column: 16
with open(filename) as file:
source = file.read()
tree = ast.parse(source, filename)
except Exception as err:
print(f"{filename}: {err.__class__.__name__}: {err}", file=sys.stderr)
tok = None
t1 = time.time()
dt = t1 - t0
print(f"Parsed in {dt:.3f} secs", file=sys.stderr)
Reported by Pylint.
Line: 18
Column: 5
tree = ast.parse(source, filename)
except Exception as err:
print(f"{filename}: {err.__class__.__name__}: {err}", file=sys.stderr)
tok = None
t1 = time.time()
dt = t1 - t0
print(f"Parsed in {dt:.3f} secs", file=sys.stderr)
print_memstats()
Reported by Pylint.
Line: 1
Column: 1
import ast
import sys
import time
from pegen.testutil import print_memstats
def main() -> None:
t0 = time.time()
Reported by Pylint.
Line: 8
Column: 1
from pegen.testutil import print_memstats
def main() -> None:
t0 = time.time()
for filename in sys.argv[1:]:
print(filename, end="\r")
try:
with open(filename) as file:
Reported by Pylint.
Line: 9
Column: 5
def main() -> None:
t0 = time.time()
for filename in sys.argv[1:]:
print(filename, end="\r")
try:
with open(filename) as file:
source = file.read()
Reported by Pylint.
Line: 19
Column: 5
except Exception as err:
print(f"{filename}: {err.__class__.__name__}: {err}", file=sys.stderr)
tok = None
t1 = time.time()
dt = t1 - t0
print(f"Parsed in {dt:.3f} secs", file=sys.stderr)
print_memstats()
Reported by Pylint.
Line: 20
Column: 5
print(f"{filename}: {err.__class__.__name__}: {err}", file=sys.stderr)
tok = None
t1 = time.time()
dt = t1 - t0
print(f"Parsed in {dt:.3f} secs", file=sys.stderr)
print_memstats()
if __name__ == "__main__":
Reported by Pylint.
Tools/scripts/rgrep.py
8 issues
Line: 17
Column: 12
bufsize = 64 * 1024
reflags = 0
opts, args = getopt.getopt(sys.argv[1:], "i")
for o, a in opts:
if o == '-i':
reflags = reflags | re.IGNORECASE
if len(args) < 2:
usage("not enough arguments")
if len(args) > 2:
Reported by Pylint.
Line: 13
Column: 1
import getopt
def main():
bufsize = 64 * 1024
reflags = 0
opts, args = getopt.getopt(sys.argv[1:], "i")
for o, a in opts:
if o == '-i':
Reported by Pylint.
Line: 13
Column: 1
import getopt
def main():
bufsize = 64 * 1024
reflags = 0
opts, args = getopt.getopt(sys.argv[1:], "i")
for o, a in opts:
if o == '-i':
Reported by Pylint.
Line: 13
Column: 1
import getopt
def main():
bufsize = 64 * 1024
reflags = 0
opts, args = getopt.getopt(sys.argv[1:], "i")
for o, a in opts:
if o == '-i':
Reported by Pylint.
Line: 17
Column: 12
bufsize = 64 * 1024
reflags = 0
opts, args = getopt.getopt(sys.argv[1:], "i")
for o, a in opts:
if o == '-i':
reflags = reflags | re.IGNORECASE
if len(args) < 2:
usage("not enough arguments")
if len(args) > 2:
Reported by Pylint.
Line: 17
Column: 9
bufsize = 64 * 1024
reflags = 0
opts, args = getopt.getopt(sys.argv[1:], "i")
for o, a in opts:
if o == '-i':
reflags = reflags | re.IGNORECASE
if len(args) < 2:
usage("not enough arguments")
if len(args) > 2:
Reported by Pylint.
Line: 30
Column: 9
except re.error as msg:
usage("error in regular expression: %s" % msg)
try:
f = open(filename)
except IOError as msg:
usage("can't open %r: %s" % (filename, msg), 1)
with f:
f.seek(0, 2)
pos = f.tell()
Reported by Pylint.
Line: 59
Column: 1
print(line)
def usage(msg, code=2):
sys.stdout = sys.stderr
print(msg)
print(__doc__)
sys.exit(code)
Reported by Pylint.
Tools/scripts/parseentities.py
8 issues
Line: 19
Column: 11
entityRE = re.compile(r'<!ENTITY +(\w+) +CDATA +"([^"]+)" +-- +((?:.|\n)+?) *-->')
def parse(text,pos=0,endpos=None):
pos = 0
if endpos is None:
endpos = len(text)
d = {}
Reported by Pylint.
Line: 34
Column: 17
pos = m.end()
return d
def writefile(f,defs):
f.write("entitydefs = {\n")
items = sorted(defs.items())
for name, (charcode,comment) in items:
if charcode[:2] == '&#':
Reported by Pylint.
Line: 15
Column: 1
Use as you like. NO WARRANTIES.
"""
import re,sys
entityRE = re.compile(r'<!ENTITY +(\w+) +CDATA +"([^"]+)" +-- +((?:.|\n)+?) *-->')
def parse(text,pos=0,endpos=None):
Reported by Pylint.
Line: 19
Column: 1
entityRE = re.compile(r'<!ENTITY +(\w+) +CDATA +"([^"]+)" +-- +((?:.|\n)+?) *-->')
def parse(text,pos=0,endpos=None):
pos = 0
if endpos is None:
endpos = len(text)
d = {}
Reported by Pylint.
Line: 24
Column: 5
pos = 0
if endpos is None:
endpos = len(text)
d = {}
while 1:
m = entityRE.search(text,pos,endpos)
if not m:
break
name,charcode,comment = m.groups()
Reported by Pylint.
Line: 26
Column: 9
endpos = len(text)
d = {}
while 1:
m = entityRE.search(text,pos,endpos)
if not m:
break
name,charcode,comment = m.groups()
d[name] = charcode,comment
pos = m.end()
Reported by Pylint.
Line: 34
Column: 1
pos = m.end()
return d
def writefile(f,defs):
f.write("entitydefs = {\n")
items = sorted(defs.items())
for name, (charcode,comment) in items:
if charcode[:2] == '&#':
Reported by Pylint.
Line: 34
Column: 1
pos = m.end()
return d
def writefile(f,defs):
f.write("entitydefs = {\n")
items = sorted(defs.items())
for name, (charcode,comment) in items:
if charcode[:2] == '&#':
Reported by Pylint.
Tools/scripts/diff.py
8 issues
Line: 11
Column: 1
"""
import sys, os, difflib, argparse
from datetime import datetime, timezone
def file_mtime(path):
t = datetime.fromtimestamp(os.stat(path).st_mtime,
timezone.utc)
Reported by Pylint.
Line: 14
Column: 1
import sys, os, difflib, argparse
from datetime import datetime, timezone
def file_mtime(path):
t = datetime.fromtimestamp(os.stat(path).st_mtime,
timezone.utc)
return t.astimezone().isoformat()
def main():
Reported by Pylint.
Line: 15
Column: 5
from datetime import datetime, timezone
def file_mtime(path):
t = datetime.fromtimestamp(os.stat(path).st_mtime,
timezone.utc)
return t.astimezone().isoformat()
def main():
Reported by Pylint.
Line: 19
Column: 1
timezone.utc)
return t.astimezone().isoformat()
def main():
parser = argparse.ArgumentParser()
parser.add_argument('-c', action='store_true', default=False,
help='Produce a context format diff (default)')
parser.add_argument('-u', action='store_true', default=False,
Reported by Pylint.
Line: 37
Column: 5
parser.add_argument('tofile')
options = parser.parse_args()
n = options.lines
fromfile = options.fromfile
tofile = options.tofile
fromdate = file_mtime(fromfile)
todate = file_mtime(tofile)
Reported by Pylint.
Line: 43
Column: 28
fromdate = file_mtime(fromfile)
todate = file_mtime(tofile)
with open(fromfile) as ff:
fromlines = ff.readlines()
with open(tofile) as tf:
tolines = tf.readlines()
if options.u:
Reported by Pylint.
Line: 45
Column: 26
todate = file_mtime(tofile)
with open(fromfile) as ff:
fromlines = ff.readlines()
with open(tofile) as tf:
tolines = tf.readlines()
if options.u:
diff = difflib.unified_diff(fromlines, tolines, fromfile, tofile, fromdate, todate, n=n)
elif options.n:
Reported by Pylint.
Line: 53
Column: 1
elif options.n:
diff = difflib.ndiff(fromlines, tolines)
elif options.m:
diff = difflib.HtmlDiff().make_file(fromlines,tolines,fromfile,tofile,context=options.c,numlines=n)
else:
diff = difflib.context_diff(fromlines, tolines, fromfile, tofile, fromdate, todate, n=n)
sys.stdout.writelines(diff)
Reported by Pylint.
Lib/test/crashers/underlying_dict.py
8 issues
Line: 1
Column: 1
import gc
thingy = object()
class A(object):
def f(self):
return 1
x = thingy
r = gc.get_referrers(thingy)
Reported by Pylint.
Line: 4
Column: 1
import gc
thingy = object()
class A(object):
def f(self):
return 1
x = thingy
r = gc.get_referrers(thingy)
Reported by Pylint.
Line: 4
Column: 1
import gc
thingy = object()
class A(object):
def f(self):
return 1
x = thingy
r = gc.get_referrers(thingy)
Reported by Pylint.
Line: 4
Column: 1
import gc
thingy = object()
class A(object):
def f(self):
return 1
x = thingy
r = gc.get_referrers(thingy)
Reported by Pylint.
Line: 4
Column: 1
import gc
thingy = object()
class A(object):
def f(self):
return 1
x = thingy
r = gc.get_referrers(thingy)
Reported by Pylint.
Line: 5
Column: 5
thingy = object()
class A(object):
def f(self):
return 1
x = thingy
r = gc.get_referrers(thingy)
if "__module__" in r[0]:
Reported by Pylint.
Line: 5
Column: 5
thingy = object()
class A(object):
def f(self):
return 1
x = thingy
r = gc.get_referrers(thingy)
if "__module__" in r[0]:
Reported by Pylint.
Line: 5
Column: 5
thingy = object()
class A(object):
def f(self):
return 1
x = thingy
r = gc.get_referrers(thingy)
if "__module__" in r[0]:
Reported by Pylint.
Lib/test/badsyntax_future4.py
8 issues
Line: 2
Column: 1
"""This is a test"""
import __future__
from __future__ import nested_scopes
def f(x):
def g(y):
return x + y
return g
Reported by Pylint.
Line: 3
Column: 1
"""This is a test"""
import __future__
from __future__ import nested_scopes
def f(x):
def g(y):
return x + y
return g
Reported by Pylint.
Line: 5
Column: 1
import __future__
from __future__ import nested_scopes
def f(x):
def g(y):
return x + y
return g
result = f(2)(4)
Reported by Pylint.
Line: 5
Column: 1
import __future__
from __future__ import nested_scopes
def f(x):
def g(y):
return x + y
return g
result = f(2)(4)
Reported by Pylint.
Line: 5
Column: 1
import __future__
from __future__ import nested_scopes
def f(x):
def g(y):
return x + y
return g
result = f(2)(4)
Reported by Pylint.
Line: 6
Column: 5
from __future__ import nested_scopes
def f(x):
def g(y):
return x + y
return g
result = f(2)(4)
Reported by Pylint.
Line: 6
Column: 5
from __future__ import nested_scopes
def f(x):
def g(y):
return x + y
return g
result = f(2)(4)
Reported by Pylint.
Line: 10
Column: 1
return x + y
return g
result = f(2)(4)
Reported by Pylint.
Lib/test/dtracedata/instance.py
8 issues
Line: 1
Column: 1
import gc
class old_style_class():
pass
class new_style_class(object):
pass
a = old_style_class()
del a
Reported by Pylint.
Line: 3
Column: 1
import gc
class old_style_class():
pass
class new_style_class(object):
pass
a = old_style_class()
del a
Reported by Pylint.
Line: 3
Column: 1
import gc
class old_style_class():
pass
class new_style_class(object):
pass
a = old_style_class()
del a
Reported by Pylint.
Line: 3
Column: 1
import gc
class old_style_class():
pass
class new_style_class(object):
pass
a = old_style_class()
del a
Reported by Pylint.
Line: 5
Column: 1
class old_style_class():
pass
class new_style_class(object):
pass
a = old_style_class()
del a
gc.collect()
Reported by Pylint.
Line: 5
Column: 1
class old_style_class():
pass
class new_style_class(object):
pass
a = old_style_class()
del a
gc.collect()
Reported by Pylint.
Line: 5
Column: 1
class old_style_class():
pass
class new_style_class(object):
pass
a = old_style_class()
del a
gc.collect()
Reported by Pylint.
Line: 5
Column: 1
class old_style_class():
pass
class new_style_class(object):
pass
a = old_style_class()
del a
gc.collect()
Reported by Pylint.
Lib/test/test_generator_stop.py
8 issues
Line: 1
Column: 1
from __future__ import generator_stop
import unittest
class TestPEP479(unittest.TestCase):
def test_stopiteration_wrapping(self):
def f():
raise StopIteration
Reported by Pylint.
Line: 6
Column: 1
import unittest
class TestPEP479(unittest.TestCase):
def test_stopiteration_wrapping(self):
def f():
raise StopIteration
def g():
yield f()
Reported by Pylint.
Line: 7
Column: 5
class TestPEP479(unittest.TestCase):
def test_stopiteration_wrapping(self):
def f():
raise StopIteration
def g():
yield f()
with self.assertRaisesRegex(RuntimeError,
Reported by Pylint.
Line: 8
Column: 9
class TestPEP479(unittest.TestCase):
def test_stopiteration_wrapping(self):
def f():
raise StopIteration
def g():
yield f()
with self.assertRaisesRegex(RuntimeError,
"generator raised StopIteration"):
Reported by Pylint.
Line: 10
Column: 9
def test_stopiteration_wrapping(self):
def f():
raise StopIteration
def g():
yield f()
with self.assertRaisesRegex(RuntimeError,
"generator raised StopIteration"):
next(g())
Reported by Pylint.
Line: 16
Column: 5
"generator raised StopIteration"):
next(g())
def test_stopiteration_wrapping_context(self):
def f():
raise StopIteration
def g():
yield f()
Reported by Pylint.
Line: 17
Column: 9
next(g())
def test_stopiteration_wrapping_context(self):
def f():
raise StopIteration
def g():
yield f()
try:
Reported by Pylint.
Line: 19
Column: 9
def test_stopiteration_wrapping_context(self):
def f():
raise StopIteration
def g():
yield f()
try:
next(g())
except RuntimeError as exc:
Reported by Pylint.
Lib/test/test_importlib/extension/test_case_sensitivity.py
8 issues
Line: 5
Column: 1
from test.support import os_helper
import unittest
import sys
from .. import util
importlib = util.import_importlib('importlib')
machinery = util.import_importlib('importlib.machinery')
Reported by Pylint.
Line: 1
Column: 1
from importlib import _bootstrap_external
from test.support import os_helper
import unittest
import sys
from .. import util
importlib = util.import_importlib('importlib')
machinery = util.import_importlib('importlib.machinery')
Reported by Pylint.
Line: 1
Column: 1
from importlib import _bootstrap_external
from test.support import os_helper
import unittest
import sys
from .. import util
importlib = util.import_importlib('importlib')
machinery = util.import_importlib('importlib.machinery')
Reported by Pylint.
Line: 13
Column: 1
@unittest.skipIf(util.EXTENSIONS.filename is None, '_testcapi not available')
@util.case_insensitive_tests
class ExtensionModuleCaseSensitivityTest(util.CASEOKTestBase):
def find_spec(self):
good_name = util.EXTENSIONS.name
bad_name = good_name.upper()
assert good_name != bad_name
Reported by Pylint.
Line: 15
Column: 5
@util.case_insensitive_tests
class ExtensionModuleCaseSensitivityTest(util.CASEOKTestBase):
def find_spec(self):
good_name = util.EXTENSIONS.name
bad_name = good_name.upper()
assert good_name != bad_name
finder = self.machinery.FileFinder(util.EXTENSIONS.path,
(self.machinery.ExtensionFileLoader,
Reported by Pylint.
Line: 18
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def find_spec(self):
good_name = util.EXTENSIONS.name
bad_name = good_name.upper()
assert good_name != bad_name
finder = self.machinery.FileFinder(util.EXTENSIONS.path,
(self.machinery.ExtensionFileLoader,
self.machinery.EXTENSION_SUFFIXES))
return finder.find_spec(bad_name)
Reported by Bandit.
Line: 25
Column: 5
return finder.find_spec(bad_name)
@unittest.skipIf(sys.flags.ignore_environment, 'ignore_environment flag was set')
def test_case_sensitive(self):
with os_helper.EnvironmentVarGuard() as env:
env.unset('PYTHONCASEOK')
self.caseok_env_changed(should_exist=False)
spec = self.find_spec()
self.assertIsNone(spec)
Reported by Pylint.
Line: 33
Column: 5
self.assertIsNone(spec)
@unittest.skipIf(sys.flags.ignore_environment, 'ignore_environment flag was set')
def test_case_insensitivity(self):
with os_helper.EnvironmentVarGuard() as env:
env.set('PYTHONCASEOK', '1')
self.caseok_env_changed(should_exist=True)
spec = self.find_spec()
self.assertTrue(spec)
Reported by Pylint.