The following issues were found
Lib/test/test_sys_setprofile.py
174 issues
Line: 93
Column: 43
class TestCaseBase(unittest.TestCase):
def check_events(self, callable, expected):
events = capture_events(callable, self.new_watcher())
if events != expected:
self.fail("Expected events:\n%s\nReceived events:\n%s"
% (pprint.pformat(expected), pprint.pformat(events)))
Reported by Pylint.
Line: 18
Column: 1
self.assertIsNone(sys.getprofile())
def test_setget(self):
def fn(*args):
pass
sys.setprofile(fn)
self.assertIs(sys.getprofile(), fn)
Reported by Pylint.
Line: 29
Column: 38
self.frames = []
self.events = []
def callback(self, frame, event, arg):
if (event == "call"
or event == "return"
or event == "exception"):
self.add_event(event, frame)
Reported by Pylint.
Line: 38
Column: 21
def add_event(self, event, frame=None):
"""Add an event to the log."""
if frame is None:
frame = sys._getframe(1)
try:
frameno = self.frames.index(frame)
except ValueError:
frameno = len(self.frames)
Reported by Pylint.
Line: 74
Column: 31
self.add_event('return', frame)
self.stack.pop()
def trace_exception(self, frame):
self.testcase.fail(
"the profiler should never receive exception events")
def trace_pass(self, frame):
pass
Reported by Pylint.
Line: 92
Column: 28
class TestCaseBase(unittest.TestCase):
def check_events(self, callable, expected):
events = capture_events(callable, self.new_watcher())
if events != expected:
self.fail("Expected events:\n%s\nReceived events:\n%s"
% (pprint.pformat(expected), pprint.pformat(events)))
Reported by Pylint.
Line: 104
Column: 15
return HookWatcher()
def test_simple(self):
def f(p):
pass
f_ident = ident(f)
self.check_events(f, [(1, 'call', f_ident),
(1, 'return', f_ident),
])
Reported by Pylint.
Line: 112
Column: 15
])
def test_exception(self):
def f(p):
1/0
f_ident = ident(f)
self.check_events(f, [(1, 'call', f_ident),
(1, 'return', f_ident),
])
Reported by Pylint.
Line: 113
Column: 13
def test_exception(self):
def f(p):
1/0
f_ident = ident(f)
self.check_events(f, [(1, 'call', f_ident),
(1, 'return', f_ident),
])
Reported by Pylint.
Line: 120
Column: 15
])
def test_caught_exception(self):
def f(p):
try: 1/0
except: pass
f_ident = ident(f)
self.check_events(f, [(1, 'call', f_ident),
(1, 'return', f_ident),
Reported by Pylint.
Lib/test/test_zlib.py
173 issues
Line: 163
Column: 13
data = decompress_func(compressed)
# Sanity check
try:
self.assertEqual(len(data), size)
self.assertEqual(len(data.strip(b'x')), 0)
finally:
data = None
Reported by Pylint.
Line: 164
Column: 13
# Sanity check
try:
self.assertEqual(len(data), size)
self.assertEqual(len(data.strip(b'x')), 0)
finally:
data = None
class CompressTestCase(BaseCompressTestCase, unittest.TestCase):
Reported by Pylint.
Line: 82
Column: 31
class ChecksumBigBufferTestCase(unittest.TestCase):
@bigmemtest(size=_4G + 4, memuse=1, dry_run=False)
def test_big_buffer(self, size):
data = b"nyan" * (_1G + 1)
self.assertEqual(zlib.crc32(data), 1044521549)
self.assertEqual(zlib.adler32(data), 2256789997)
Reported by Pylint.
Line: 299
Column: 9
for i in range(0, len(data), 256):
bufs.append(co.compress(data[i:i+256]))
bufs.append(co.flush())
combuf = b''.join(bufs)
dco = zlib.decompressobj()
y1 = dco.decompress(b''.join(bufs))
y2 = dco.flush()
self.assertEqual(data, y1 + y2)
Reported by Pylint.
Line: 478
Column: 9
'requires zlib.Z_SYNC_FLUSH')
def test_odd_flush(self):
# Test for odd flushing bugs noted in 2.0, and hopefully fixed in 2.1
import random
# Testing on 17K of "random" data
# Create compressor and decompressor objects
co = zlib.compressobj(zlib.Z_BEST_COMPRESSION)
dco = zlib.decompressobj()
Reported by Pylint.
Line: 478
Column: 9
'requires zlib.Z_SYNC_FLUSH')
def test_odd_flush(self):
# Test for odd flushing bugs noted in 2.0, and hopefully fixed in 2.1
import random
# Testing on 17K of "random" data
# Create compressor and decompressor objects
co = zlib.compressobj(zlib.Z_BEST_COMPRESSION)
dco = zlib.decompressobj()
Reported by Pylint.
Line: 630
Column: 9
@bigmemtest(size=_4G, memuse=1)
def test_flush_large_length(self, size):
# Test flush(length) parameter greater than internal limit UINT_MAX
input = HAMLET_SCENE * 10
data = zlib.compress(input, 1)
dco = zlib.decompressobj()
dco.decompress(data, 1)
self.assertEqual(dco.flush(size), input[1:])
Reported by Pylint.
Line: 637
Column: 9
self.assertEqual(dco.flush(size), input[1:])
def test_flush_custom_length(self):
input = HAMLET_SCENE * 10
data = zlib.compress(input, 1)
dco = zlib.decompressobj()
dco.decompress(data, 1)
self.assertEqual(dco.flush(CustomInt()), input[1:])
Reported by Pylint.
Line: 1
Column: 1
import unittest
from test import support
from test.support import import_helper
import binascii
import copy
import pickle
import random
import sys
from test.support import bigmemtest, _1G, _4G
Reported by Pylint.
Line: 6
Suggestion:
https://bandit.readthedocs.io/en/latest/blacklists/blacklist_imports.html#b403-import-pickle
from test.support import import_helper
import binascii
import copy
import pickle
import random
import sys
from test.support import bigmemtest, _1G, _4G
Reported by Bandit.
Lib/unittest/mock.py
173 issues
Line: 809
Column: 59
message = 'expected %s not found.\nExpected: %s\nActual: %s'
expected_string = self._format_mock_call_signature(args, kwargs)
call_args = self.call_args
actual_string = self._format_mock_call_signature(*call_args)
return message % (action, expected_string, actual_string)
def _get_call_signature_from_name(self, name):
"""
Reported by Pylint.
Line: 1114
Column: 9
def _increment_mock_call(self, /, *args, **kwargs):
self.called = True
self.call_count += 1
# handle call_args
# needs to be set here so assertions on call arguments pass before
# execution in the case of awaited calls
_call = _Call((args, kwargs), two=True)
Reported by Pylint.
Line: 2174
Column: 30
self.__dict__['_mock_await_args'] = None
self.__dict__['_mock_await_args_list'] = _CallList()
code_mock = NonCallableMock(spec_set=CodeType)
code_mock.co_flags = inspect.CO_COROUTINE
self.__dict__['__code__'] = code_mock
async def _execute_mock_call(self, /, *args, **kwargs):
# This is nearly just like super(), except for special handling
# of coroutines
Reported by Pylint.
Line: 2927
Column: 30
def __init__(self, iterator):
self.iterator = iterator
code_mock = NonCallableMock(spec_set=CodeType)
code_mock.co_flags = inspect.CO_ITERABLE_COROUTINE
self.__dict__['__code__'] = code_mock
async def __anext__(self):
try:
return next(self.iterator)
Reported by Pylint.
Line: 123
Column: 18
if sig is None:
return
func, sig = sig
def checksig(self, /, *args, **kwargs):
sig.bind(*args, **kwargs)
_copy_func_details(func, checksig)
type(mock)._mock_check_sig = checksig
type(mock).__signature__ = sig
Reported by Pylint.
Line: 126
Column: 5
def checksig(self, /, *args, **kwargs):
sig.bind(*args, **kwargs)
_copy_func_details(func, checksig)
type(mock)._mock_check_sig = checksig
type(mock).__signature__ = sig
def _copy_func_details(func, funcopy):
# we explicitly don't copy func.__dict__ into this copy as it would
Reported by Pylint.
Line: 195
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b102_exec_used.html
src = """def %s(*args, **kwargs):
_checksig_(*args, **kwargs)
return mock(*args, **kwargs)""" % name
exec (src, context)
funcopy = context[name]
_setup_func(funcopy, mock, sig)
return funcopy
Reported by Bandit.
Line: 195
Column: 5
src = """def %s(*args, **kwargs):
_checksig_(*args, **kwargs)
return mock(*args, **kwargs)""" % name
exec (src, context)
funcopy = context[name]
_setup_func(funcopy, mock, sig)
return funcopy
Reported by Pylint.
Line: 235
Column: 30
funcopy.return_value = mock.return_value
funcopy.side_effect = mock.side_effect
funcopy._mock_children = mock._mock_children
funcopy.assert_called_with = assert_called_with
funcopy.assert_called_once_with = assert_called_once_with
funcopy.assert_has_calls = assert_has_calls
funcopy.assert_any_call = assert_any_call
Reported by Pylint.
Line: 235
Column: 5
funcopy.return_value = mock.return_value
funcopy.side_effect = mock.side_effect
funcopy._mock_children = mock._mock_children
funcopy.assert_called_with = assert_called_with
funcopy.assert_called_once_with = assert_called_once_with
funcopy.assert_has_calls = assert_has_calls
funcopy.assert_any_call = assert_any_call
Reported by Pylint.
Lib/test/test_urlparse.py
173 issues
Line: 146
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b108_hardcoded_tmp_directory.html
def test_roundtrips(self):
str_cases = [
('file:///tmp/junk.txt',
('file', '', '/tmp/junk.txt', '', '', ''),
('file', '', '/tmp/junk.txt', '', '')),
('imap://mail.python.org/mbox1',
('imap', 'mail.python.org', '/mbox1', '', '', ''),
('imap', 'mail.python.org', '/mbox1', '', '')),
('mms://wms.sys.hinet.net/cts/Drama/09006251100.asf',
Reported by Bandit.
Line: 147
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b108_hardcoded_tmp_directory.html
str_cases = [
('file:///tmp/junk.txt',
('file', '', '/tmp/junk.txt', '', '', ''),
('file', '', '/tmp/junk.txt', '', '')),
('imap://mail.python.org/mbox1',
('imap', 'mail.python.org', '/mbox1', '', '', ''),
('imap', 'mail.python.org', '/mbox1', '', '')),
('mms://wms.sys.hinet.net/cts/Drama/09006251100.asf',
('mms', 'wms.sys.hinet.net', '/cts/Drama/09006251100.asf',
Reported by Bandit.
Line: 219
Column: 9
def checkJoin(self, base, relurl, expected):
str_components = (base, relurl, expected)
self.assertEqual(urllib.parse.urljoin(base, relurl), expected)
bytes_components = baseb, relurlb, expectedb = [
x.encode('ascii') for x in str_components]
self.assertEqual(urllib.parse.urljoin(baseb, relurlb), expectedb)
def test_unparse_parse(self):
str_cases = ['Python', './Python','x-newscheme://foo.com/stuff','x://y','x:/y','x:/','/',]
Reported by Pylint.
Line: 271
Column: 3
#self.checkJoin(RFC1808_BASE, 'http:g', 'http:g')
#self.checkJoin(RFC1808_BASE, 'http:', 'http:')
# XXX: The following tests are no longer compatible with RFC3986
# self.checkJoin(RFC1808_BASE, '../../../g', 'http://a/../g')
# self.checkJoin(RFC1808_BASE, '../../../../g', 'http://a/../../g')
# self.checkJoin(RFC1808_BASE, '/./g', 'http://a/./g')
# self.checkJoin(RFC1808_BASE, '/../g', 'http://a/../g')
Reported by Pylint.
Line: 322
Column: 3
self.checkJoin(RFC2396_BASE, 'g#s/./x', 'http://a/b/c/g#s/./x')
self.checkJoin(RFC2396_BASE, 'g#s/../x', 'http://a/b/c/g#s/../x')
# XXX: The following tests are no longer compatible with RFC3986
# self.checkJoin(RFC2396_BASE, '../../../g', 'http://a/../g')
# self.checkJoin(RFC2396_BASE, '../../../../g', 'http://a/../../g')
# self.checkJoin(RFC2396_BASE, '/./g', 'http://a/./g')
# self.checkJoin(RFC2396_BASE, '/../g', 'http://a/../g')
Reported by Pylint.
Line: 421
Column: 3
self.checkJoin('ws://a/b','g','ws://a/g')
self.checkJoin('wss://a/b','g','wss://a/g')
# XXX: The following tests are no longer compatible with RFC3986
# self.checkJoin(SIMPLE_BASE, '../../../g','http://a/../g')
# self.checkJoin(SIMPLE_BASE, '/./g','http://a/./g')
# test for issue22118 duplicate slashes
self.checkJoin(SIMPLE_BASE + '/', 'foo', SIMPLE_BASE + '/foo')
Reported by Pylint.
Line: 613
Column: 13
url = b"HTTP://WWW.PYTHON.ORG:65536/doc/#frag"
p = urllib.parse.urlsplit(url)
with self.assertRaisesRegex(ValueError, "out of range"):
p.port
def test_urlsplit_remove_unsafe_bytes(self):
# Remove ASCII tabs and newlines from input
url = "http\t://www.python\n.org\t/java\nscript:\talert('msg\r\n')/?query\n=\tsomething#frag\nment"
p = urllib.parse.urlsplit(url)
Reported by Pylint.
Line: 654
Column: 13
def test_attributes_bad_port(self):
"""Check handling of invalid ports."""
for bytes in (False, True):
for parse in (urllib.parse.urlsplit, urllib.parse.urlparse):
for port in ("foo", "1.5", "-1", "0x10"):
with self.subTest(bytes=bytes, parse=parse, port=port):
netloc = "www.example.net:" + port
url = "http://" + netloc
Reported by Pylint.
Line: 666
Column: 29
p = parse(url)
self.assertEqual(p.netloc, netloc)
with self.assertRaises(ValueError):
p.port
def test_attributes_without_netloc(self):
# This example is straight from RFC 3261. It looks like it
# should allow the username, hostname, and port to be filled
# in, but doesn't. Since it's a URI and doesn't use the
Reported by Pylint.
Line: 852
Column: 22
def _check_result_type(self, str_type):
num_args = len(str_type._fields)
bytes_type = str_type._encoded_counterpart
self.assertIs(bytes_type._decoded_counterpart, str_type)
str_args = ('',) * num_args
bytes_args = (b'',) * num_args
str_result = str_type(*str_args)
bytes_result = bytes_type(*bytes_args)
Reported by Pylint.
Lib/pstats.py
173 issues
Line: 53
Column: 13
obj = str.__new__(cls, value)
obj._value_ = value
for other_value in values[1:]:
cls._value2member_map_[other_value] = obj
obj._all_values = values
return obj
@dataclass(unsafe_hash=True)
Reported by Pylint.
Line: 139
Column: 13
def load_stats(self, arg):
if arg is None:
self.stats = {}
return
elif isinstance(arg, str):
with open(arg, 'rb') as f:
self.stats = marshal.load(f)
try:
Reported by Pylint.
Line: 143
Column: 17
return
elif isinstance(arg, str):
with open(arg, 'rb') as f:
self.stats = marshal.load(f)
try:
file_stats = os.stat(arg)
arg = time.ctime(file_stats.st_mtime) + " " + arg
except: # in case this is not unix
pass
Reported by Pylint.
Line: 143
Suggestion:
https://bandit.readthedocs.io/en/latest/blacklists/blacklist_calls.html#b302-marshal
return
elif isinstance(arg, str):
with open(arg, 'rb') as f:
self.stats = marshal.load(f)
try:
file_stats = os.stat(arg)
arg = time.ctime(file_stats.st_mtime) + " " + arg
except: # in case this is not unix
pass
Reported by Bandit.
Line: 147
Column: 13
try:
file_stats = os.stat(arg)
arg = time.ctime(file_stats.st_mtime) + " " + arg
except: # in case this is not unix
pass
self.files = [arg]
elif hasattr(arg, 'create_stats'):
arg.create_stats()
self.stats = arg.stats
Reported by Pylint.
Line: 149
Column: 13
arg = time.ctime(file_stats.st_mtime) + " " + arg
except: # in case this is not unix
pass
self.files = [arg]
elif hasattr(arg, 'create_stats'):
arg.create_stats()
self.stats = arg.stats
arg.stats = {}
if not self.stats:
Reported by Pylint.
Line: 152
Column: 13
self.files = [arg]
elif hasattr(arg, 'create_stats'):
arg.create_stats()
self.stats = arg.stats
arg.stats = {}
if not self.stats:
raise TypeError("Cannot create or construct a %r object from %r"
% (self.__class__, arg))
return
Reported by Pylint.
Line: 160
Column: 32
return
def get_top_level_stats(self):
for func, (cc, nc, tt, ct, callers) in self.stats.items():
self.total_calls += nc
self.prim_calls += cc
self.total_tt += tt
if ("jprofile", 0, "profiler") in callers:
self.top_level.add(func)
Reported by Pylint.
Line: 167
Column: 17
if ("jprofile", 0, "profiler") in callers:
self.top_level.add(func)
if len(func_std_string(func)) > self.max_name_len:
self.max_name_len = len(func_std_string(func))
def add(self, *arg_list):
if not arg_list:
return self
for item in reversed(arg_list):
Reported by Pylint.
Line: 221
Column: 13
def get_sort_arg_defs(self):
"""Expand all abbreviations that are unique."""
if not self.sort_arg_dict:
self.sort_arg_dict = dict = {}
bad_list = {}
for word, tup in self.sort_arg_dict_default.items():
fragment = word
while fragment:
if not fragment:
Reported by Pylint.
Lib/test/test_pickle.py
172 issues
Line: 96
Column: 13
def dumps(self, arg, proto=None):
class PersPickler(self.pickler):
def persistent_id(subself, obj):
return self.persistent_id(obj)
f = io.BytesIO()
p = PersPickler(f, proto)
p.dump(arg)
return f.getvalue()
Reported by Pylint.
Line: 105
Column: 13
def loads(self, buf, **kwds):
class PersUnpickler(self.unpickler):
def persistent_load(subself, obj):
return self.persistent_load(obj)
f = io.BytesIO(buf)
u = PersUnpickler(f, **kwds)
return u.load()
Reported by Pylint.
Line: 140
Column: 13
self.assertIsNone(r())
class PersPickler(self.pickler):
def persistent_id(subself, obj):
return obj
check(PersPickler)
class PersPickler(self.pickler):
@classmethod
Reported by Pylint.
Line: 144
Column: 9
return obj
check(PersPickler)
class PersPickler(self.pickler):
@classmethod
def persistent_id(cls, obj):
return obj
check(PersPickler)
Reported by Pylint.
Line: 150
Column: 9
return obj
check(PersPickler)
class PersPickler(self.pickler):
@staticmethod
def persistent_id(obj):
return obj
check(PersPickler)
Reported by Pylint.
Line: 169
Column: 13
self.assertIsNone(r())
class PersUnpickler(self.unpickler):
def persistent_load(subself, pid):
return pid
check(PersUnpickler)
class PersUnpickler(self.unpickler):
@classmethod
Reported by Pylint.
Line: 173
Column: 9
return pid
check(PersUnpickler)
class PersUnpickler(self.unpickler):
@classmethod
def persistent_load(cls, pid):
return pid
check(PersUnpickler)
Reported by Pylint.
Line: 179
Column: 9
return pid
check(PersUnpickler)
class PersUnpickler(self.unpickler):
@staticmethod
def persistent_load(pid):
return pid
check(PersUnpickler)
Reported by Pylint.
Line: 491
Column: 28
ResourceWarning,
StopAsyncIteration,
RecursionError,
EncodingWarning):
continue
if exc is not OSError and issubclass(exc, OSError):
self.assertEqual(reverse_mapping('builtins', name),
('exceptions', 'OSError'))
elif exc is not ImportError and issubclass(exc, ImportError):
Reported by Pylint.
Line: 35
Column: 25
class PyPickleTests(AbstractPickleModuleTests):
dump = staticmethod(pickle._dump)
dumps = staticmethod(pickle._dumps)
load = staticmethod(pickle._load)
loads = staticmethod(pickle._loads)
Pickler = pickle._Pickler
Unpickler = pickle._Unpickler
Reported by Pylint.
Lib/asyncio/base_events.py
172 issues
Line: 28
Column: 1
import subprocess
import threading
import time
import traceback
import sys
import warnings
import weakref
try:
Reported by Pylint.
Line: 38
Column: 1
except ImportError: # pragma: no cover
ssl = None
from . import constants
from . import coroutines
from . import events
from . import exceptions
from . import futures
from . import protocols
Reported by Pylint.
Line: 39
Column: 1
ssl = None
from . import constants
from . import coroutines
from . import events
from . import exceptions
from . import futures
from . import protocols
from . import sslproto
Reported by Pylint.
Line: 40
Column: 1
from . import constants
from . import coroutines
from . import events
from . import exceptions
from . import futures
from . import protocols
from . import sslproto
from . import staggered
Reported by Pylint.
Line: 41
Column: 1
from . import constants
from . import coroutines
from . import events
from . import exceptions
from . import futures
from . import protocols
from . import sslproto
from . import staggered
from . import tasks
Reported by Pylint.
Line: 42
Column: 1
from . import coroutines
from . import events
from . import exceptions
from . import futures
from . import protocols
from . import sslproto
from . import staggered
from . import tasks
from . import transports
Reported by Pylint.
Line: 43
Column: 1
from . import events
from . import exceptions
from . import futures
from . import protocols
from . import sslproto
from . import staggered
from . import tasks
from . import transports
from . import trsock
Reported by Pylint.
Line: 44
Column: 1
from . import exceptions
from . import futures
from . import protocols
from . import sslproto
from . import staggered
from . import tasks
from . import transports
from . import trsock
from .log import logger
Reported by Pylint.
Line: 45
Column: 1
from . import futures
from . import protocols
from . import sslproto
from . import staggered
from . import tasks
from . import transports
from . import trsock
from .log import logger
Reported by Pylint.
Line: 46
Column: 1
from . import protocols
from . import sslproto
from . import staggered
from . import tasks
from . import transports
from . import trsock
from .log import logger
Reported by Pylint.
Lib/_pyio.py
172 issues
Line: 14
Column: 5
# Import _thread instead of threading to reduce startup cost
from _thread import allocate_lock as Lock
if sys.platform in {'win32', 'cygwin'}:
from msvcrt import setmode as _setmode
else:
_setmode = None
import io
from io import (__all__, SEEK_SET, SEEK_CUR, SEEK_END)
Reported by Pylint.
Line: 62
Column: 27
if sys.flags.warn_default_encoding:
import warnings
warnings.warn("'encoding' argument not specified.",
EncodingWarning, stacklevel + 1)
return encoding
# Wrapper for builtins.open
#
Reported by Pylint.
Line: 562
Column: 29
# For backwards compatibility, a (slowish) readline().
if hasattr(self, "peek"):
def nreadahead():
readahead = self.peek(1)
if not readahead:
return 1
n = (readahead.find(b"\n") + 1) or len(readahead)
if size >= 0:
n = min(n, size)
Reported by Pylint.
Line: 583
Column: 17
size = size_index()
res = bytearray()
while size < 0 or len(res) < size:
b = self.read(nreadahead())
if not b:
break
res += b
if res.endswith(b"\n"):
break
Reported by Pylint.
Line: 627
Column: 13
"""
self._checkClosed()
for line in lines:
self.write(line)
io.IOBase.register(IOBase)
class RawIOBase(IOBase):
Reported by Pylint.
Line: 657
Column: 9
if size < 0:
return self.readall()
b = bytearray(size.__index__())
n = self.readinto(b)
if n is None:
return None
del b[n:]
return bytes(b)
Reported by Pylint.
Line: 772
Column: 13
b = b.cast('B')
if read1:
data = self.read1(len(b))
else:
data = self.read(len(b))
n = len(data)
b[:n] = data
Reported by Pylint.
Line: 774
Column: 13
if read1:
data = self.read1(len(b))
else:
data = self.read(len(b))
n = len(data)
b[:n] = data
return n
Reported by Pylint.
Line: 1500
Column: 1
return BufferedWriter.write(self, b)
class FileIO(RawIOBase):
_fd = -1
_created = False
_readable = False
_writable = False
_appending = False
Reported by Pylint.
Line: 1612
Column: 30
if _setmode:
# don't translate newlines (\r\n <=> \n)
_setmode(fd, os.O_BINARY)
self.name = file
if self._appending:
# For consistent behaviour, we explicitly seek to the
# end of file (otherwise, it might be done only on the
Reported by Pylint.
Lib/optparse.py
171 issues
Line: 633
Column: 12
# -- Constructor validation methods --------------------------------
def _check_action(self):
if self.action is None:
self.action = "store"
elif self.action not in self.ACTIONS:
raise OptionError("invalid action: %r" % self.action, self)
def _check_type(self):
Reported by Pylint.
Line: 639
Column: 12
raise OptionError("invalid action: %r" % self.action, self)
def _check_type(self):
if self.type is None:
if self.action in self.ALWAYS_TYPED_ACTIONS:
if self.choices is not None:
# The "choices" attribute implies "choice" type.
self.type = "choice"
else:
Reported by Pylint.
Line: 641
Column: 20
def _check_type(self):
if self.type is None:
if self.action in self.ALWAYS_TYPED_ACTIONS:
if self.choices is not None:
# The "choices" attribute implies "choice" type.
self.type = "choice"
else:
# No type given? "string" is the most sensible default.
self.type = "string"
Reported by Pylint.
Line: 664
Column: 16
def _check_choice(self):
if self.type == "choice":
if self.choices is None:
raise OptionError(
"must supply a list of choices for type 'choice'", self)
elif not isinstance(self.choices, (tuple, list)):
raise OptionError(
"choices must be a list of strings ('%s' supplied)"
Reported by Pylint.
Line: 667
Column: 33
if self.choices is None:
raise OptionError(
"must supply a list of choices for type 'choice'", self)
elif not isinstance(self.choices, (tuple, list)):
raise OptionError(
"choices must be a list of strings ('%s' supplied)"
% str(type(self.choices)).split("'")[1], self)
elif self.choices is not None:
raise OptionError(
Reported by Pylint.
Line: 670
Column: 32
elif not isinstance(self.choices, (tuple, list)):
raise OptionError(
"choices must be a list of strings ('%s' supplied)"
% str(type(self.choices)).split("'")[1], self)
elif self.choices is not None:
raise OptionError(
"must not supply choices for type %r" % self.type, self)
def _check_dest(self):
Reported by Pylint.
Line: 671
Column: 14
raise OptionError(
"choices must be a list of strings ('%s' supplied)"
% str(type(self.choices)).split("'")[1], self)
elif self.choices is not None:
raise OptionError(
"must not supply choices for type %r" % self.type, self)
def _check_dest(self):
# No destination given, and we need one for this action. The
Reported by Pylint.
Line: 680
Column: 12
# self.type check is for callbacks that take a value.
takes_value = (self.action in self.STORE_ACTIONS or
self.type is not None)
if self.dest is None and takes_value:
# Glean a destination from the first long option string,
# or from the first short option string if no long options.
if self._long_opts:
# eg. "--foo-bar" -> "foo_bar"
Reported by Pylint.
Line: 691
Column: 54
self.dest = self._short_opts[0][1]
def _check_const(self):
if self.action not in self.CONST_ACTIONS and self.const is not None:
raise OptionError(
"'const' must not be supplied for action %r" % self.action,
self)
def _check_nargs(self):
Reported by Pylint.
Line: 698
Column: 16
def _check_nargs(self):
if self.action in self.TYPED_ACTIONS:
if self.nargs is None:
self.nargs = 1
elif self.nargs is not None:
raise OptionError(
"'nargs' must not be supplied for action %r" % self.action,
self)
Reported by Pylint.
Lib/test/test_call.py
170 issues
Line: 190
Column: 13
def test_varargs(self):
self.assertEqual(
self.obj.meth_varargs(1, 2, 3),
(self.expected_self, (1, 2, 3)),
)
def test_varargs_ext(self):
self.assertEqual(
Reported by Pylint.
Line: 196
Column: 13
def test_varargs_ext(self):
self.assertEqual(
self.obj.meth_varargs(*(1, 2, 3)),
(self.expected_self, (1, 2, 3)),
)
def test_varargs_error_kw(self):
msg = r"meth_varargs\(\) takes no keyword arguments"
Reported by Pylint.
Line: 203
Column: 37
def test_varargs_error_kw(self):
msg = r"meth_varargs\(\) takes no keyword arguments"
self.assertRaisesRegex(
TypeError, msg, lambda: self.obj.meth_varargs(k=1),
)
def test_varargs_keywords(self):
self.assertEqual(
self.obj.meth_varargs_keywords(1, 2, a=3, b=4),
Reported by Pylint.
Line: 208
Column: 13
def test_varargs_keywords(self):
self.assertEqual(
self.obj.meth_varargs_keywords(1, 2, a=3, b=4),
(self.expected_self, (1, 2), {'a': 3, 'b': 4})
)
def test_varargs_keywords_ext(self):
self.assertEqual(
Reported by Pylint.
Line: 214
Column: 13
def test_varargs_keywords_ext(self):
self.assertEqual(
self.obj.meth_varargs_keywords(*[1, 2], **{'a': 3, 'b': 4}),
(self.expected_self, (1, 2), {'a': 3, 'b': 4})
)
def test_o(self):
self.assertEqual(self.obj.meth_o(1), (self.expected_self, 1))
Reported by Pylint.
Line: 219
Column: 26
)
def test_o(self):
self.assertEqual(self.obj.meth_o(1), (self.expected_self, 1))
def test_o_ext(self):
self.assertEqual(self.obj.meth_o(*[1]), (self.expected_self, 1))
def test_o_error_no_arg(self):
Reported by Pylint.
Line: 222
Column: 26
self.assertEqual(self.obj.meth_o(1), (self.expected_self, 1))
def test_o_ext(self):
self.assertEqual(self.obj.meth_o(*[1]), (self.expected_self, 1))
def test_o_error_no_arg(self):
msg = r"meth_o\(\) takes exactly one argument \(0 given\)"
self.assertRaisesRegex(TypeError, msg, self.obj.meth_o)
Reported by Pylint.
Line: 226
Column: 48
def test_o_error_no_arg(self):
msg = r"meth_o\(\) takes exactly one argument \(0 given\)"
self.assertRaisesRegex(TypeError, msg, self.obj.meth_o)
def test_o_error_two_args(self):
msg = r"meth_o\(\) takes exactly one argument \(2 given\)"
self.assertRaisesRegex(
TypeError, msg, lambda: self.obj.meth_o(1, 2),
Reported by Pylint.
Line: 231
Column: 37
def test_o_error_two_args(self):
msg = r"meth_o\(\) takes exactly one argument \(2 given\)"
self.assertRaisesRegex(
TypeError, msg, lambda: self.obj.meth_o(1, 2),
)
def test_o_error_ext(self):
msg = r"meth_o\(\) takes exactly one argument \(3 given\)"
self.assertRaisesRegex(
Reported by Pylint.
Line: 237
Column: 37
def test_o_error_ext(self):
msg = r"meth_o\(\) takes exactly one argument \(3 given\)"
self.assertRaisesRegex(
TypeError, msg, lambda: self.obj.meth_o(*(1, 2, 3)),
)
def test_o_error_kw(self):
msg = r"meth_o\(\) takes no keyword arguments"
self.assertRaisesRegex(
Reported by Pylint.