The following issues were found
Lib/test/test_asyncio/test_base_events.py
412 issues
Line: 44
Column: 5
m_socket.socket = mock.MagicMock()
m_socket.socket.return_value = test_utils.mock_nonblocking_socket()
m_socket.getaddrinfo._is_coroutine = False
return m_socket
def patch_socket(f):
Reported by Pylint.
Line: 67
Column: 13
self.assertEqual(
(INET, STREAM, TCP, '', ('1.2.3.4', 1)),
base_events._ipaddr_info('1.2.3.4', 1, INET, STREAM, TCP))
self.assertEqual(
(INET, STREAM, TCP, '', ('1.2.3.4', 1)),
base_events._ipaddr_info(b'1.2.3.4', 1, INET, STREAM, TCP))
Reported by Pylint.
Line: 71
Column: 13
self.assertEqual(
(INET, STREAM, TCP, '', ('1.2.3.4', 1)),
base_events._ipaddr_info(b'1.2.3.4', 1, INET, STREAM, TCP))
self.assertEqual(
(INET, STREAM, TCP, '', ('1.2.3.4', 1)),
base_events._ipaddr_info('1.2.3.4', 1, UNSPEC, STREAM, TCP))
Reported by Pylint.
Line: 75
Column: 13
self.assertEqual(
(INET, STREAM, TCP, '', ('1.2.3.4', 1)),
base_events._ipaddr_info('1.2.3.4', 1, UNSPEC, STREAM, TCP))
self.assertEqual(
(INET, DGRAM, UDP, '', ('1.2.3.4', 1)),
base_events._ipaddr_info('1.2.3.4', 1, UNSPEC, DGRAM, UDP))
Reported by Pylint.
Line: 79
Column: 13
self.assertEqual(
(INET, DGRAM, UDP, '', ('1.2.3.4', 1)),
base_events._ipaddr_info('1.2.3.4', 1, UNSPEC, DGRAM, UDP))
# Socket type STREAM implies TCP protocol.
self.assertEqual(
(INET, STREAM, TCP, '', ('1.2.3.4', 1)),
base_events._ipaddr_info('1.2.3.4', 1, UNSPEC, STREAM, 0))
Reported by Pylint.
Line: 84
Column: 13
# Socket type STREAM implies TCP protocol.
self.assertEqual(
(INET, STREAM, TCP, '', ('1.2.3.4', 1)),
base_events._ipaddr_info('1.2.3.4', 1, UNSPEC, STREAM, 0))
# Socket type DGRAM implies UDP protocol.
self.assertEqual(
(INET, DGRAM, UDP, '', ('1.2.3.4', 1)),
base_events._ipaddr_info('1.2.3.4', 1, UNSPEC, DGRAM, 0))
Reported by Pylint.
Line: 89
Column: 13
# Socket type DGRAM implies UDP protocol.
self.assertEqual(
(INET, DGRAM, UDP, '', ('1.2.3.4', 1)),
base_events._ipaddr_info('1.2.3.4', 1, UNSPEC, DGRAM, 0))
# No socket type.
self.assertIsNone(
base_events._ipaddr_info('1.2.3.4', 1, UNSPEC, 0, 0))
Reported by Pylint.
Line: 93
Column: 13
# No socket type.
self.assertIsNone(
base_events._ipaddr_info('1.2.3.4', 1, UNSPEC, 0, 0))
if socket_helper.IPV6_ENABLED:
# IPv4 address with family IPv6.
self.assertIsNone(
base_events._ipaddr_info('1.2.3.4', 1, INET6, STREAM, TCP))
Reported by Pylint.
Line: 98
Column: 17
if socket_helper.IPV6_ENABLED:
# IPv4 address with family IPv6.
self.assertIsNone(
base_events._ipaddr_info('1.2.3.4', 1, INET6, STREAM, TCP))
self.assertEqual(
(INET6, STREAM, TCP, '', ('::3', 1, 0, 0)),
base_events._ipaddr_info('::3', 1, INET6, STREAM, TCP))
Reported by Pylint.
Line: 102
Column: 17
self.assertEqual(
(INET6, STREAM, TCP, '', ('::3', 1, 0, 0)),
base_events._ipaddr_info('::3', 1, INET6, STREAM, TCP))
self.assertEqual(
(INET6, STREAM, TCP, '', ('::3', 1, 0, 0)),
base_events._ipaddr_info('::3', 1, UNSPEC, STREAM, TCP))
Reported by Pylint.
Lib/test/test_contextlib.py
412 issues
Line: 29
Column: 13
pass
with self.assertRaises(TypeError):
MissingExit()
def test_structural_subclassing(self):
class ManagerFromScratch:
def __enter__(self):
return self
Reported by Pylint.
Line: 94
Column: 9
def whee():
yield
ctx = whee()
ctx.__enter__()
# Calling __exit__ should not result in an exception
self.assertFalse(ctx.__exit__(TypeError, TypeError("foo"), None))
def test_contextmanager_trap_yield_after_throw(self):
@contextmanager
Reported by Pylint.
Line: 96
Column: 26
ctx = whee()
ctx.__enter__()
# Calling __exit__ should not result in an exception
self.assertFalse(ctx.__exit__(TypeError, TypeError("foo"), None))
def test_contextmanager_trap_yield_after_throw(self):
@contextmanager
def whoo():
try:
Reported by Pylint.
Line: 106
Column: 9
except:
yield
ctx = whoo()
ctx.__enter__()
self.assertRaises(
RuntimeError, ctx.__exit__, TypeError, TypeError("foo"), None
)
def test_contextmanager_except(self):
Reported by Pylint.
Line: 108
Column: 27
ctx = whoo()
ctx.__enter__()
self.assertRaises(
RuntimeError, ctx.__exit__, TypeError, TypeError("foo"), None
)
def test_contextmanager_except(self):
state = []
@contextmanager
Reported by Pylint.
Line: 249
Column: 13
yield
with self.assertRaises(TypeError):
woohoo()
with self.assertRaises(TypeError):
woohoo(3, 5)
with self.assertRaises(TypeError):
woohoo(b=3)
Reported by Pylint.
Line: 249
Column: 13
yield
with self.assertRaises(TypeError):
woohoo()
with self.assertRaises(TypeError):
woohoo(3, 5)
with self.assertRaises(TypeError):
woohoo(b=3)
Reported by Pylint.
Line: 251
Column: 13
with self.assertRaises(TypeError):
woohoo()
with self.assertRaises(TypeError):
woohoo(3, 5)
with self.assertRaises(TypeError):
woohoo(b=3)
def test_recursive(self):
depth = 0
Reported by Pylint.
Line: 251
Column: 13
with self.assertRaises(TypeError):
woohoo()
with self.assertRaises(TypeError):
woohoo(3, 5)
with self.assertRaises(TypeError):
woohoo(b=3)
def test_recursive(self):
depth = 0
Reported by Pylint.
Line: 253
Column: 13
with self.assertRaises(TypeError):
woohoo(3, 5)
with self.assertRaises(TypeError):
woohoo(b=3)
def test_recursive(self):
depth = 0
@contextmanager
def woohoo():
Reported by Pylint.
Lib/test/test_shutil.py
402 issues
Line: 636
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b103_set_bad_file_permissions.html
dst_dir = os.path.join(tmp_dir, 'destination')
self.addCleanup(shutil.rmtree, tmp_dir)
os.chmod(src_dir, 0o777)
write_file((src_dir, 'permissive.txt'), '123')
os.chmod(os.path.join(src_dir, 'permissive.txt'), 0o777)
write_file((src_dir, 'restrictive.txt'), '456')
os.chmod(os.path.join(src_dir, 'restrictive.txt'), 0o600)
restrictive_subdir = tempfile.mkdtemp(dir=src_dir)
Reported by Bandit.
Line: 638
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b103_set_bad_file_permissions.html
os.chmod(src_dir, 0o777)
write_file((src_dir, 'permissive.txt'), '123')
os.chmod(os.path.join(src_dir, 'permissive.txt'), 0o777)
write_file((src_dir, 'restrictive.txt'), '456')
os.chmod(os.path.join(src_dir, 'restrictive.txt'), 0o600)
restrictive_subdir = tempfile.mkdtemp(dir=src_dir)
self.addCleanup(os_helper.rmtree, restrictive_subdir)
os.chmod(restrictive_subdir, 0o600)
Reported by Bandit.
Line: 179
Column: 9
Returns the path of the directory.
"""
d = tempfile.mkdtemp(prefix=prefix, dir=os.getcwd())
self.addCleanup(os_helper.rmtree, d)
return d
class TestRmTree(BaseTest, unittest.TestCase):
Reported by Pylint.
Line: 504
Column: 13
os.symlink(os.path.join(src_dir, 'file.txt'),
src_link)
if hasattr(os, 'lchmod'):
os.lchmod(src_link, stat.S_IRWXU | stat.S_IRWXO)
if hasattr(os, 'lchflags') and hasattr(stat, 'UF_NODUMP'):
os.lchflags(src_link, stat.UF_NODUMP)
src_stat = os.lstat(src_link)
shutil.copytree(src_dir, dst_dir, symlinks=True)
self.assertTrue(os.path.islink(os.path.join(dst_dir, 'sub', 'link')))
Reported by Pylint.
Line: 506
Column: 13
if hasattr(os, 'lchmod'):
os.lchmod(src_link, stat.S_IRWXU | stat.S_IRWXO)
if hasattr(os, 'lchflags') and hasattr(stat, 'UF_NODUMP'):
os.lchflags(src_link, stat.UF_NODUMP)
src_stat = os.lstat(src_link)
shutil.copytree(src_dir, dst_dir, symlinks=True)
self.assertTrue(os.path.islink(os.path.join(dst_dir, 'sub', 'link')))
actual = os.readlink(os.path.join(dst_dir, 'sub', 'link'))
# Bad practice to blindly strip the prefix as it may be required to
Reported by Pylint.
Line: 841
Column: 9
os.symlink(dst, dst_link)
os.chmod(src, stat.S_IRWXU|stat.S_IRWXG)
os.chmod(dst, stat.S_IRWXU)
os.lchmod(src_link, stat.S_IRWXO|stat.S_IRWXG)
# link to link
os.lchmod(dst_link, stat.S_IRWXO)
shutil.copymode(src_link, dst_link, follow_symlinks=False)
self.assertEqual(os.lstat(src_link).st_mode,
os.lstat(dst_link).st_mode)
Reported by Pylint.
Line: 843
Column: 9
os.chmod(dst, stat.S_IRWXU)
os.lchmod(src_link, stat.S_IRWXO|stat.S_IRWXG)
# link to link
os.lchmod(dst_link, stat.S_IRWXO)
shutil.copymode(src_link, dst_link, follow_symlinks=False)
self.assertEqual(os.lstat(src_link).st_mode,
os.lstat(dst_link).st_mode)
self.assertNotEqual(os.stat(src).st_mode, os.stat(dst).st_mode)
# src link - use chmod
Reported by Pylint.
Line: 849
Column: 9
os.lstat(dst_link).st_mode)
self.assertNotEqual(os.stat(src).st_mode, os.stat(dst).st_mode)
# src link - use chmod
os.lchmod(dst_link, stat.S_IRWXO)
shutil.copymode(src_link, dst, follow_symlinks=False)
self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode)
# dst link - use chmod
os.lchmod(dst_link, stat.S_IRWXO)
shutil.copymode(src, dst_link, follow_symlinks=False)
Reported by Pylint.
Line: 853
Column: 9
shutil.copymode(src_link, dst, follow_symlinks=False)
self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode)
# dst link - use chmod
os.lchmod(dst_link, stat.S_IRWXO)
shutil.copymode(src, dst_link, follow_symlinks=False)
self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode)
@unittest.skipIf(hasattr(os, 'lchmod'), 'requires os.lchmod to be missing')
@os_helper.skip_unless_symlink
Reported by Pylint.
Line: 889
Column: 13
os.symlink(src, src_link)
os.symlink(dst, dst_link)
if hasattr(os, 'lchmod'):
os.lchmod(src_link, stat.S_IRWXO)
if hasattr(os, 'lchflags') and hasattr(stat, 'UF_NODUMP'):
os.lchflags(src_link, stat.UF_NODUMP)
src_link_stat = os.lstat(src_link)
# follow
if hasattr(os, 'lchmod'):
Reported by Pylint.
Lib/test/test_random.py
402 issues
Line: 23
Column: 17
def randomlist(self, n):
"""Helper function to make a list of random numbers"""
return [self.gen.random() for i in range(n)]
def test_autoseed(self):
self.gen.seed()
state1 = self.gen.getstate()
time.sleep(0.1)
Reported by Pylint.
Line: 26
Column: 9
return [self.gen.random() for i in range(n)]
def test_autoseed(self):
self.gen.seed()
state1 = self.gen.getstate()
time.sleep(0.1)
self.gen.seed() # different seeds at different times
state2 = self.gen.getstate()
self.assertNotEqual(state1, state2)
Reported by Pylint.
Line: 27
Column: 18
def test_autoseed(self):
self.gen.seed()
state1 = self.gen.getstate()
time.sleep(0.1)
self.gen.seed() # different seeds at different times
state2 = self.gen.getstate()
self.assertNotEqual(state1, state2)
Reported by Pylint.
Line: 29
Column: 9
self.gen.seed()
state1 = self.gen.getstate()
time.sleep(0.1)
self.gen.seed() # different seeds at different times
state2 = self.gen.getstate()
self.assertNotEqual(state1, state2)
def test_saverestore(self):
N = 1000
Reported by Pylint.
Line: 30
Column: 18
state1 = self.gen.getstate()
time.sleep(0.1)
self.gen.seed() # different seeds at different times
state2 = self.gen.getstate()
self.assertNotEqual(state1, state2)
def test_saverestore(self):
N = 1000
self.gen.seed()
Reported by Pylint.
Line: 31
Column: 9
time.sleep(0.1)
self.gen.seed() # different seeds at different times
state2 = self.gen.getstate()
self.assertNotEqual(state1, state2)
def test_saverestore(self):
N = 1000
self.gen.seed()
state = self.gen.getstate()
Reported by Pylint.
Line: 35
Column: 9
def test_saverestore(self):
N = 1000
self.gen.seed()
state = self.gen.getstate()
randseq = self.randomlist(N)
self.gen.setstate(state) # should regenerate the same sequence
self.assertEqual(randseq, self.randomlist(N))
Reported by Pylint.
Line: 36
Column: 17
def test_saverestore(self):
N = 1000
self.gen.seed()
state = self.gen.getstate()
randseq = self.randomlist(N)
self.gen.setstate(state) # should regenerate the same sequence
self.assertEqual(randseq, self.randomlist(N))
def test_seedargs(self):
Reported by Pylint.
Line: 38
Column: 9
self.gen.seed()
state = self.gen.getstate()
randseq = self.randomlist(N)
self.gen.setstate(state) # should regenerate the same sequence
self.assertEqual(randseq, self.randomlist(N))
def test_seedargs(self):
# Seed value with a negative hash.
class MySeed(object):
Reported by Pylint.
Line: 39
Column: 9
state = self.gen.getstate()
randseq = self.randomlist(N)
self.gen.setstate(state) # should regenerate the same sequence
self.assertEqual(randseq, self.randomlist(N))
def test_seedargs(self):
# Seed value with a negative hash.
class MySeed(object):
def __hash__(self):
Reported by Pylint.
Lib/test/test_traceback.py
401 issues
Line: 18
Column: 1
import os
import textwrap
import traceback
from functools import partial
test_code = namedtuple('code', ['co_filename', 'co_name'])
test_code.co_positions = lambda _: iter([(6, 6, 0, 0)])
Reported by Pylint.
Line: 400
Column: 24
def test_caret_in_type_annotation(self):
def f_with_type():
def foo(a: THIS_DOES_NOT_EXIST ) -> int:
return 0
lineno_f = f_with_type.__code__.co_firstlineno
expected_f = (
'Traceback (most recent call last):\n'
Reported by Pylint.
Line: 499
Column: 20
def test_caret_for_subscript(self):
def f_with_subscript():
some_dict = {'x': {'y': None}}
return some_dict['x']['y']['z']
lineno_f = f_with_subscript.__code__.co_firstlineno
expected_error = (
'Traceback (most recent call last):\n'
f' File "{__file__}", line {self.callable_line}, in get_exception\n'
Reported by Pylint.
Line: 995
Column: 13
def check_zero_div(self, msg):
lines = msg.splitlines()
if has_no_debug_ranges():
self.assertTrue(lines[-3].startswith(' File'))
self.assertIn('1/0 # In zero_div', lines[-2])
else:
self.assertTrue(lines[-4].startswith(' File'))
self.assertIn('1/0 # In zero_div', lines[-3])
self.assertTrue(lines[-1].startswith('ZeroDivisionError'), lines[-1])
Reported by Pylint.
Line: 996
Column: 13
lines = msg.splitlines()
if has_no_debug_ranges():
self.assertTrue(lines[-3].startswith(' File'))
self.assertIn('1/0 # In zero_div', lines[-2])
else:
self.assertTrue(lines[-4].startswith(' File'))
self.assertIn('1/0 # In zero_div', lines[-3])
self.assertTrue(lines[-1].startswith('ZeroDivisionError'), lines[-1])
Reported by Pylint.
Line: 998
Column: 13
self.assertTrue(lines[-3].startswith(' File'))
self.assertIn('1/0 # In zero_div', lines[-2])
else:
self.assertTrue(lines[-4].startswith(' File'))
self.assertIn('1/0 # In zero_div', lines[-3])
self.assertTrue(lines[-1].startswith('ZeroDivisionError'), lines[-1])
def test_simple(self):
try:
Reported by Pylint.
Line: 999
Column: 13
self.assertIn('1/0 # In zero_div', lines[-2])
else:
self.assertTrue(lines[-4].startswith(' File'))
self.assertIn('1/0 # In zero_div', lines[-3])
self.assertTrue(lines[-1].startswith('ZeroDivisionError'), lines[-1])
def test_simple(self):
try:
1/0 # Marker
Reported by Pylint.
Line: 1000
Column: 9
else:
self.assertTrue(lines[-4].startswith(' File'))
self.assertIn('1/0 # In zero_div', lines[-3])
self.assertTrue(lines[-1].startswith('ZeroDivisionError'), lines[-1])
def test_simple(self):
try:
1/0 # Marker
except ZeroDivisionError as _:
Reported by Pylint.
Line: 1007
Column: 17
1/0 # Marker
except ZeroDivisionError as _:
e = _
lines = self.get_report(e).splitlines()
if has_no_debug_ranges():
self.assertEqual(len(lines), 4)
self.assertTrue(lines[3].startswith('ZeroDivisionError'))
else:
self.assertEqual(len(lines), 5)
Reported by Pylint.
Line: 1009
Column: 13
e = _
lines = self.get_report(e).splitlines()
if has_no_debug_ranges():
self.assertEqual(len(lines), 4)
self.assertTrue(lines[3].startswith('ZeroDivisionError'))
else:
self.assertEqual(len(lines), 5)
self.assertTrue(lines[4].startswith('ZeroDivisionError'))
self.assertTrue(lines[0].startswith('Traceback'))
Reported by Pylint.
Lib/test/string_tests.py
400 issues
Line: 42
Column: 20
# these arguments to the appropriate type
def fixtype(self, obj):
if isinstance(obj, str):
return self.__class__.type2test(obj)
elif isinstance(obj, list):
return [self.fixtype(x) for x in obj]
elif isinstance(obj, tuple):
return tuple([self.fixtype(x) for x in obj])
elif isinstance(obj, dict):
Reported by Pylint.
Line: 56
Column: 9
return obj
def test_fixtype(self):
self.assertIs(type(self.fixtype("123")), self.type2test)
# check that obj.method(*args) returns result
def checkequal(self, result, obj, methodname, *args, **kwargs):
result = self.fixtype(result)
obj = self.fixtype(obj)
Reported by Pylint.
Line: 65
Column: 9
args = self.fixtype(args)
kwargs = {k: self.fixtype(v) for k,v in kwargs.items()}
realresult = getattr(obj, methodname)(*args, **kwargs)
self.assertEqual(
result,
realresult
)
# if the original is returned make sure that
# this doesn't happen with subclasses
Reported by Pylint.
Line: 73
Column: 17
# this doesn't happen with subclasses
if obj is realresult:
try:
class subtype(self.__class__.type2test):
pass
except TypeError:
pass # Skip this if we can't subclass
else:
obj = subtype(obj)
Reported by Pylint.
Line: 80
Column: 17
else:
obj = subtype(obj)
realresult = getattr(obj, methodname)(*args)
self.assertIsNot(obj, realresult)
# check that obj.method(*args) raises exc
def checkraises(self, exc, obj, methodname, *args, expected_msg=None):
obj = self.fixtype(obj)
args = self.fixtype(args)
Reported by Pylint.
Line: 86
Column: 14
def checkraises(self, exc, obj, methodname, *args, expected_msg=None):
obj = self.fixtype(obj)
args = self.fixtype(args)
with self.assertRaises(exc) as cm:
getattr(obj, methodname)(*args)
self.assertNotEqual(str(cm.exception), '')
if expected_msg is not None:
self.assertEqual(str(cm.exception), expected_msg)
Reported by Pylint.
Line: 88
Column: 9
args = self.fixtype(args)
with self.assertRaises(exc) as cm:
getattr(obj, methodname)(*args)
self.assertNotEqual(str(cm.exception), '')
if expected_msg is not None:
self.assertEqual(str(cm.exception), expected_msg)
# call obj.method(*args) without any checks
def checkcall(self, obj, methodname, *args):
Reported by Pylint.
Line: 90
Column: 13
getattr(obj, methodname)(*args)
self.assertNotEqual(str(cm.exception), '')
if expected_msg is not None:
self.assertEqual(str(cm.exception), expected_msg)
# call obj.method(*args) without any checks
def checkcall(self, obj, methodname, *args):
obj = self.fixtype(obj)
args = self.fixtype(args)
Reported by Pylint.
Line: 159
Column: 21
else:
r2, rem = len(i)+1, 0
if rem or r1 != r2:
self.assertEqual(rem, 0, '%s != 0 for %s' % (rem, i))
self.assertEqual(r1, r2, '%s != %s for %s' % (r1, r2, i))
def test_find(self):
self.checkequal(0, 'abcdefghiabc', 'find', 'abc')
self.checkequal(9, 'abcdefghiabc', 'find', 'abc', 1)
Reported by Pylint.
Line: 160
Column: 21
r2, rem = len(i)+1, 0
if rem or r1 != r2:
self.assertEqual(rem, 0, '%s != 0 for %s' % (rem, i))
self.assertEqual(r1, r2, '%s != %s for %s' % (r1, r2, i))
def test_find(self):
self.checkequal(0, 'abcdefghiabc', 'find', 'abc')
self.checkequal(9, 'abcdefghiabc', 'find', 'abc', 1)
self.checkequal(-1, 'abcdefghiabc', 'find', 'def', 4)
Reported by Pylint.
Lib/test/test_email/test__header_value_parser.py
396 issues
Line: 17
Column: 26
self.assertEqual(x, ' \t')
self.assertEqual(str(x), '')
self.assertEqual(x.value, '')
self.assertEqual(x.token_type, 'fws')
class TestParserMixin:
def _assert_results(self, tl, rest, string, value, defects, remainder,
Reported by Pylint.
Line: 70
Column: 26
def test_get_fws_only(self):
fws = self._test_get_x(parser.get_fws, ' \t ', ' \t ', ' ', [], '')
self.assertEqual(fws.token_type, 'fws')
def test_get_fws_space(self):
self._test_get_x(parser.get_fws, ' foo', ' ', ' ', [], 'foo')
def test_get_fws_ws_run(self):
Reported by Pylint.
Line: 398
Column: 5
[errors.InvalidHeaderDefect],
'')
def test_get_unstructured_invalid_ew(self):
self._test_get_x(self._get_unst,
'=?utf-8?q?=somevalue?=',
'=?utf-8?q?=somevalue?=',
'=?utf-8?q?=somevalue?=',
[],
Reported by Pylint.
Line: 419
Column: 26
def test_get_qp_ctext_only(self):
ptext = self._test_get_x(parser.get_qp_ctext,
'foobar', 'foobar', ' ', [], '')
self.assertEqual(ptext.token_type, 'ptext')
def test_get_qp_ctext_all_printables(self):
with_qp = self.rfc_printable_ascii.replace('\\', '\\\\')
with_qp = with_qp. replace('(', r'\(')
with_qp = with_qp.replace(')', r'\)')
Reported by Pylint.
Line: 464
Column: 26
ptext = self._test_get_x(parser.get_qp_ctext,
'foo\x00bar)', 'foo\x00bar', ' ',
[errors.NonPrintableDefect], ')')
self.assertEqual(ptext.defects[0].non_printables[0], '\x00')
# get_qcontent
def test_get_qcontent_only(self):
ptext = self._test_get_x(parser.get_qcontent,
Reported by Pylint.
Line: 471
Column: 26
def test_get_qcontent_only(self):
ptext = self._test_get_x(parser.get_qcontent,
'foobar', 'foobar', 'foobar', [], '')
self.assertEqual(ptext.token_type, 'ptext')
def test_get_qcontent_all_printables(self):
with_qp = self.rfc_printable_ascii.replace('\\', '\\\\')
with_qp = with_qp. replace('"', r'\"')
ptext = self._test_get_x(parser.get_qcontent, with_qp,
Reported by Pylint.
Line: 504
Column: 26
ptext = self._test_get_x(parser.get_qcontent,
'foo\x00fg"', 'foo\x00fg', 'foo\x00fg',
[errors.NonPrintableDefect], '"')
self.assertEqual(ptext.defects[0].non_printables[0], '\x00')
# get_atext
def test_get_atext_only(self):
atext = self._test_get_x(parser.get_atext,
Reported by Pylint.
Line: 511
Column: 26
def test_get_atext_only(self):
atext = self._test_get_x(parser.get_atext,
'foobar', 'foobar', 'foobar', [], '')
self.assertEqual(atext.token_type, 'atext')
def test_get_atext_all_atext(self):
atext = self._test_get_x(parser.get_atext, self.rfc_atext_chars,
self.rfc_atext_chars,
self.rfc_atext_chars, [], '')
Reported by Pylint.
Line: 534
Column: 26
atext = self._test_get_x(parser.get_atext,
'foo\x00bar(', 'foo\x00bar', 'foo\x00bar',
[errors.NonPrintableDefect], '(')
self.assertEqual(atext.defects[0].non_printables[0], '\x00')
# get_bare_quoted_string
def test_get_bare_quoted_string_only(self):
bqs = self._test_get_x(parser.get_bare_quoted_string,
Reported by Pylint.
Line: 1225
Column: 26
def test_get_dtext_only(self):
dtext = self._test_get_x(parser.get_dtext,
'foobar', 'foobar', 'foobar', [], '')
self.assertEqual(dtext.token_type, 'ptext')
def test_get_dtext_all_dtext(self):
dtext = self._test_get_x(parser.get_dtext, self.rfc_dtext_chars,
self.rfc_dtext_chars,
self.rfc_dtext_chars, [], '')
Reported by Pylint.
Lib/pydoc.py
395 issues
Line: 1583
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b605_start_process_with_a_shell.html
(fd, filename) = tempfile.mkstemp()
os.close(fd)
try:
if hasattr(os, 'system') and os.system('more "%s"' % filename) == 0:
return lambda text: pipepager(text, 'more')
else:
return ttypager
finally:
os.unlink(filename)
Reported by Bandit.
Line: 1597
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b602_subprocess_popen_with_shell_equals_true.html
def pipepager(text, cmd):
"""Page through text by feeding it to another program."""
import subprocess
proc = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE,
errors='backslashreplace')
try:
with proc.stdin as pipe:
try:
pipe.write(text)
Reported by Bandit.
Line: 1625
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b605_start_process_with_a_shell.html
with open(filename, 'w', errors='backslashreplace') as file:
file.write(text)
try:
os.system(cmd + ' "' + filename + '"')
finally:
os.unlink(filename)
def _escape_stdout(text):
# Escape non-encodable characters to avoid encoding errors later
Reported by Bandit.
Line: 76
Column: 1
import warnings
from collections import deque
from reprlib import Repr
from traceback import format_exception_only
# --------------------------------------------------------- common routines
def pathdirs():
Reported by Pylint.
Line: 85
Column: 9
"""Convert sys.path into a list of absolute, existing, unique paths."""
dirs = []
normdirs = []
for dir in sys.path:
dir = os.path.abspath(dir or '.')
normdir = os.path.normcase(dir)
if normdir not in normdirs and os.path.isdir(dir):
dirs.append(dir)
normdirs.append(normdir)
Reported by Pylint.
Line: 147
Column: 13
return None
for base in cls.__mro__:
try:
doc = _getowndoc(getattr(base, name))
except AttributeError:
continue
if doc is not None:
return doc
return None
Reported by Pylint.
Line: 158
Column: 9
"""Get the documentation string for an object if it is not
inherited from its class."""
try:
doc = object.__getattribute__(obj, '__doc__')
if doc is None:
return None
if obj is not type:
typedoc = type(obj).__doc__
if isinstance(typedoc, str) and typedoc == doc:
Reported by Pylint.
Line: 169
Column: 13
except AttributeError:
return None
def _getdoc(object):
"""Get the documentation string for an object.
All tabs are expanded to spaces. To clean up docstrings that are
indented to line up with blocks of code, any whitespace than can be
uniformly removed from the second line onwards is removed."""
Reported by Pylint.
Line: 175
Column: 5
All tabs are expanded to spaces. To clean up docstrings that are
indented to line up with blocks of code, any whitespace than can be
uniformly removed from the second line onwards is removed."""
doc = _getowndoc(object)
if doc is None:
try:
doc = _finddoc(object)
except (AttributeError, TypeError):
return None
Reported by Pylint.
Line: 185
Column: 12
return None
return inspect.cleandoc(doc)
def getdoc(object):
"""Get the doc string or comments for an object."""
result = _getdoc(object) or inspect.getcomments(object)
return result and re.sub('^ *\n', '', result.rstrip()) or ''
def splitdoc(doc):
Reported by Pylint.
Lib/test/test_posix.py
394 issues
Line: 52
Column: 9
pass
self.teardown_files = [ os_helper.TESTFN ]
self._warnings_manager = warnings_helper.check_warnings()
self._warnings_manager.__enter__()
warnings.filterwarnings('ignore', '.* potential security risk .*',
RuntimeWarning)
def tearDown(self):
for teardown_file in self.teardown_files:
Reported by Pylint.
Line: 59
Column: 9
def tearDown(self):
for teardown_file in self.teardown_files:
os_helper.unlink(teardown_file)
self._warnings_manager.__exit__(None, None, None)
def testNoArgFunctions(self):
# test posix functions which take no arguments and have
# no side-effects which we need to cleanup (e.g., fork, wait, abort)
NO_ARG_FUNCTIONS = [ "ctermid", "getcwd", "getcwdb", "uname",
Reported by Pylint.
Line: 583
Column: 34
'test needs posix.O_EXLOCK')
def test_osexlock(self):
fd = os.open(os_helper.TESTFN,
os.O_WRONLY|os.O_EXLOCK|os.O_CREAT)
self.assertRaises(OSError, os.open, os_helper.TESTFN,
os.O_WRONLY|os.O_EXLOCK|os.O_NONBLOCK)
os.close(fd)
if hasattr(posix, "O_SHLOCK"):
Reported by Pylint.
Line: 585
Column: 39
fd = os.open(os_helper.TESTFN,
os.O_WRONLY|os.O_EXLOCK|os.O_CREAT)
self.assertRaises(OSError, os.open, os_helper.TESTFN,
os.O_WRONLY|os.O_EXLOCK|os.O_NONBLOCK)
os.close(fd)
if hasattr(posix, "O_SHLOCK"):
fd = os.open(os_helper.TESTFN,
os.O_WRONLY|os.O_SHLOCK|os.O_CREAT)
Reported by Pylint.
Line: 590
Column: 38
if hasattr(posix, "O_SHLOCK"):
fd = os.open(os_helper.TESTFN,
os.O_WRONLY|os.O_SHLOCK|os.O_CREAT)
self.assertRaises(OSError, os.open, os_helper.TESTFN,
os.O_WRONLY|os.O_EXLOCK|os.O_NONBLOCK)
os.close(fd)
@unittest.skipUnless(hasattr(posix, 'O_SHLOCK'),
Reported by Pylint.
Line: 592
Column: 43
fd = os.open(os_helper.TESTFN,
os.O_WRONLY|os.O_SHLOCK|os.O_CREAT)
self.assertRaises(OSError, os.open, os_helper.TESTFN,
os.O_WRONLY|os.O_EXLOCK|os.O_NONBLOCK)
os.close(fd)
@unittest.skipUnless(hasattr(posix, 'O_SHLOCK'),
'test needs posix.O_SHLOCK')
def test_osshlock(self):
Reported by Pylint.
Line: 599
Column: 34
'test needs posix.O_SHLOCK')
def test_osshlock(self):
fd1 = os.open(os_helper.TESTFN,
os.O_WRONLY|os.O_SHLOCK|os.O_CREAT)
fd2 = os.open(os_helper.TESTFN,
os.O_WRONLY|os.O_SHLOCK|os.O_CREAT)
os.close(fd2)
os.close(fd1)
Reported by Pylint.
Line: 601
Column: 35
fd1 = os.open(os_helper.TESTFN,
os.O_WRONLY|os.O_SHLOCK|os.O_CREAT)
fd2 = os.open(os_helper.TESTFN,
os.O_WRONLY|os.O_SHLOCK|os.O_CREAT)
os.close(fd2)
os.close(fd1)
if hasattr(posix, "O_EXLOCK"):
fd = os.open(os_helper.TESTFN,
Reported by Pylint.
Line: 607
Column: 38
if hasattr(posix, "O_EXLOCK"):
fd = os.open(os_helper.TESTFN,
os.O_WRONLY|os.O_SHLOCK|os.O_CREAT)
self.assertRaises(OSError, os.open, os_helper.TESTFN,
os.O_RDONLY|os.O_EXLOCK|os.O_NONBLOCK)
os.close(fd)
@unittest.skipUnless(hasattr(posix, 'fstat'),
Reported by Pylint.
Line: 609
Column: 43
fd = os.open(os_helper.TESTFN,
os.O_WRONLY|os.O_SHLOCK|os.O_CREAT)
self.assertRaises(OSError, os.open, os_helper.TESTFN,
os.O_RDONLY|os.O_EXLOCK|os.O_NONBLOCK)
os.close(fd)
@unittest.skipUnless(hasattr(posix, 'fstat'),
'test needs posix.fstat()')
def test_fstat(self):
Reported by Pylint.
Lib/test/test_math.py
385 issues
Line: 381
Column: 38
self.assertTrue(math.isnan(math.atan2(NAN, NAN)))
def testCbrt(self):
self.assertRaises(TypeError, math.cbrt)
self.ftest('cbrt(0)', math.cbrt(0), 0)
self.ftest('cbrt(1)', math.cbrt(1), 1)
self.ftest('cbrt(8)', math.cbrt(8), 2)
self.ftest('cbrt(0.0)', math.cbrt(0.0), 0.0)
self.ftest('cbrt(-0.0)', math.cbrt(-0.0), -0.0)
Reported by Pylint.
Line: 382
Column: 31
def testCbrt(self):
self.assertRaises(TypeError, math.cbrt)
self.ftest('cbrt(0)', math.cbrt(0), 0)
self.ftest('cbrt(1)', math.cbrt(1), 1)
self.ftest('cbrt(8)', math.cbrt(8), 2)
self.ftest('cbrt(0.0)', math.cbrt(0.0), 0.0)
self.ftest('cbrt(-0.0)', math.cbrt(-0.0), -0.0)
self.ftest('cbrt(1.2)', math.cbrt(1.2), 1.062658569182611)
Reported by Pylint.
Line: 383
Column: 31
def testCbrt(self):
self.assertRaises(TypeError, math.cbrt)
self.ftest('cbrt(0)', math.cbrt(0), 0)
self.ftest('cbrt(1)', math.cbrt(1), 1)
self.ftest('cbrt(8)', math.cbrt(8), 2)
self.ftest('cbrt(0.0)', math.cbrt(0.0), 0.0)
self.ftest('cbrt(-0.0)', math.cbrt(-0.0), -0.0)
self.ftest('cbrt(1.2)', math.cbrt(1.2), 1.062658569182611)
self.ftest('cbrt(-2.6)', math.cbrt(-2.6), -1.375068867074141)
Reported by Pylint.
Line: 384
Column: 31
self.assertRaises(TypeError, math.cbrt)
self.ftest('cbrt(0)', math.cbrt(0), 0)
self.ftest('cbrt(1)', math.cbrt(1), 1)
self.ftest('cbrt(8)', math.cbrt(8), 2)
self.ftest('cbrt(0.0)', math.cbrt(0.0), 0.0)
self.ftest('cbrt(-0.0)', math.cbrt(-0.0), -0.0)
self.ftest('cbrt(1.2)', math.cbrt(1.2), 1.062658569182611)
self.ftest('cbrt(-2.6)', math.cbrt(-2.6), -1.375068867074141)
self.ftest('cbrt(27)', math.cbrt(27), 3)
Reported by Pylint.
Line: 385
Column: 33
self.ftest('cbrt(0)', math.cbrt(0), 0)
self.ftest('cbrt(1)', math.cbrt(1), 1)
self.ftest('cbrt(8)', math.cbrt(8), 2)
self.ftest('cbrt(0.0)', math.cbrt(0.0), 0.0)
self.ftest('cbrt(-0.0)', math.cbrt(-0.0), -0.0)
self.ftest('cbrt(1.2)', math.cbrt(1.2), 1.062658569182611)
self.ftest('cbrt(-2.6)', math.cbrt(-2.6), -1.375068867074141)
self.ftest('cbrt(27)', math.cbrt(27), 3)
self.ftest('cbrt(-1)', math.cbrt(-1), -1)
Reported by Pylint.
Line: 386
Column: 34
self.ftest('cbrt(1)', math.cbrt(1), 1)
self.ftest('cbrt(8)', math.cbrt(8), 2)
self.ftest('cbrt(0.0)', math.cbrt(0.0), 0.0)
self.ftest('cbrt(-0.0)', math.cbrt(-0.0), -0.0)
self.ftest('cbrt(1.2)', math.cbrt(1.2), 1.062658569182611)
self.ftest('cbrt(-2.6)', math.cbrt(-2.6), -1.375068867074141)
self.ftest('cbrt(27)', math.cbrt(27), 3)
self.ftest('cbrt(-1)', math.cbrt(-1), -1)
self.ftest('cbrt(-27)', math.cbrt(-27), -3)
Reported by Pylint.
Line: 387
Column: 33
self.ftest('cbrt(8)', math.cbrt(8), 2)
self.ftest('cbrt(0.0)', math.cbrt(0.0), 0.0)
self.ftest('cbrt(-0.0)', math.cbrt(-0.0), -0.0)
self.ftest('cbrt(1.2)', math.cbrt(1.2), 1.062658569182611)
self.ftest('cbrt(-2.6)', math.cbrt(-2.6), -1.375068867074141)
self.ftest('cbrt(27)', math.cbrt(27), 3)
self.ftest('cbrt(-1)', math.cbrt(-1), -1)
self.ftest('cbrt(-27)', math.cbrt(-27), -3)
self.assertEqual(math.cbrt(INF), INF)
Reported by Pylint.
Line: 388
Column: 34
self.ftest('cbrt(0.0)', math.cbrt(0.0), 0.0)
self.ftest('cbrt(-0.0)', math.cbrt(-0.0), -0.0)
self.ftest('cbrt(1.2)', math.cbrt(1.2), 1.062658569182611)
self.ftest('cbrt(-2.6)', math.cbrt(-2.6), -1.375068867074141)
self.ftest('cbrt(27)', math.cbrt(27), 3)
self.ftest('cbrt(-1)', math.cbrt(-1), -1)
self.ftest('cbrt(-27)', math.cbrt(-27), -3)
self.assertEqual(math.cbrt(INF), INF)
self.assertEqual(math.cbrt(NINF), NINF)
Reported by Pylint.
Line: 389
Column: 32
self.ftest('cbrt(-0.0)', math.cbrt(-0.0), -0.0)
self.ftest('cbrt(1.2)', math.cbrt(1.2), 1.062658569182611)
self.ftest('cbrt(-2.6)', math.cbrt(-2.6), -1.375068867074141)
self.ftest('cbrt(27)', math.cbrt(27), 3)
self.ftest('cbrt(-1)', math.cbrt(-1), -1)
self.ftest('cbrt(-27)', math.cbrt(-27), -3)
self.assertEqual(math.cbrt(INF), INF)
self.assertEqual(math.cbrt(NINF), NINF)
self.assertTrue(math.isnan(math.cbrt(NAN)))
Reported by Pylint.
Line: 390
Column: 32
self.ftest('cbrt(1.2)', math.cbrt(1.2), 1.062658569182611)
self.ftest('cbrt(-2.6)', math.cbrt(-2.6), -1.375068867074141)
self.ftest('cbrt(27)', math.cbrt(27), 3)
self.ftest('cbrt(-1)', math.cbrt(-1), -1)
self.ftest('cbrt(-27)', math.cbrt(-27), -3)
self.assertEqual(math.cbrt(INF), INF)
self.assertEqual(math.cbrt(NINF), NINF)
self.assertTrue(math.isnan(math.cbrt(NAN)))
Reported by Pylint.