Commit 2832922f authored by Jason Madden's avatar Jason Madden

Updates for new pylint.

parent 3be12a03
......@@ -288,7 +288,7 @@ jobs:
# TODO: Revisit this when we have caching of that part.
run: |
pip install -U pylint
python -m pylint --limit-inference-results=1 --rcfile=.pylintrc gevent
python -m pylint --rcfile=.pylintrc gevent
- name: "Tests: Basic"
run: |
python -m gevent.tests --second-chance $G_USE_COV
......
......@@ -80,7 +80,7 @@ try:
# deprecated. Avoid that warning.
import _imp as imp
except ImportError:
import imp
import imp # pylint:disable=deprecated-module
imp_acquire_lock = imp.acquire_lock
imp_release_lock = imp.release_lock
......
......@@ -332,7 +332,7 @@ def assign_standard_callbacks(ffi, lib, callbacks_class, extras=()): # pylint:di
# callbacks keeps these cdata objects alive at the python level
callbacks = callbacks_class(ffi)
extras = [extra if len(extra) == 2 else (extra, None) for extra in extras]
extras = tuple([(getattr(callbacks, name), error) for name, error in extras])
extras = tuple((getattr(callbacks, name), error) for name, error in extras)
for (func, error_func) in (
(callbacks.python_callback, None),
(callbacks.python_handle_error, None),
......
......@@ -230,7 +230,7 @@ class PeriodicMonitoringThread(object):
if not did_block:
return
active_greenlet = did_block[1]
active_greenlet = did_block[1] # pylint:disable=unsubscriptable-object
report = self._greenlet_tracer.did_block_hub_report(
hub, active_greenlet,
dict(greenlet_stacks=False, current_thread_ident=self.monitor_thread_ident))
......
# (No idea where this comes from; it warns about 'configuration')
# pylint:disable=invalid-all-format
# Wrapper module for _ssl. Written by Bill Janssen.
# Ported to gevent by Denis Bilenko.
"""
......@@ -324,7 +326,7 @@ class SSLSocket(socket):
else:
raise
def connect(self, addr):
def connect(self, addr): # renamed addr -> address in Python 3 pylint:disable=arguments-renamed
"""Connects to remote ADDR, and then wraps the connection in
an SSL channel."""
# Here we assume that the socket is client-side, and not
......
......@@ -186,13 +186,13 @@ class SSLContext(orig_SSLContext):
def sni_callback(self, value):
if value and callable(value):
value = _Callback(value)
super(orig_SSLContext, orig_SSLContext).sni_callback.__set__(self, value)
super(orig_SSLContext, orig_SSLContext).sni_callback.__set__(self, value) # pylint:disable=no-member
else:
# In newer versions, this just sets sni_callback.
def set_servername_callback(self, cb): # pylint:disable=arguments-differ
if cb and callable(cb):
cb = _Callback(cb)
super().set_servername_callback(cb)
def set_servername_callback(self, server_name_callback):
if server_name_callback and callable(server_name_callback):
server_name_callback = _Callback(server_name_callback)
super().set_servername_callback(server_name_callback)
class SSLSocket(socket):
......@@ -681,7 +681,7 @@ class SSLSocket(socket):
if not self.server_hostname:
raise ValueError("check_hostname needs server_hostname "
"argument")
match_hostname(self.getpeercert(), self.server_hostname)
match_hostname(self.getpeercert(), self.server_hostname) # pylint:disable=deprecated-method
if hasattr(SSLObject, '_create'):
# 3.7+, making it difficult to create these objects.
......
......@@ -629,12 +629,12 @@ class SSLSocket(socket):
self._sslobj = None
raise
def connect(self, addr):
def connect(self, addr): # pylint:disable=arguments-renamed
"""Connects to remote ADDR, and then wraps the connection in
an SSL channel."""
self._real_connect(addr, False)
def connect_ex(self, addr):
def connect_ex(self, addr): # pylint:disable=arguments-renamed
"""Connects to remote ADDR, and then wraps the connection in
an SSL channel."""
return self._real_connect(addr, True)
......
......@@ -51,7 +51,7 @@ __all__ = [
try:
from collections.abc import Mapping
except ImportError:
from collections import Mapping
from collections import Mapping # pylint:disable=deprecated-class
from gevent._compat import PY37
from gevent._util import _NONE
......
......@@ -25,6 +25,7 @@ libev = _corecffi.lib # pylint:disable=no-member
if hasattr(libev, 'vfd_open'):
# Must be on windows
# pylint:disable=c-extension-no-member
assert sys.platform.startswith("win"), "vfd functions only needed on windows"
vfd_open = libev.vfd_open
vfd_free = libev.vfd_free
......@@ -52,7 +53,7 @@ from gevent._ffi.loop import AbstractCallbacks
from gevent._ffi.loop import assign_standard_callbacks
class _Callbacks(AbstractCallbacks):
# pylint:disable=arguments-differ
# pylint:disable=arguments-differ,arguments-renamed
def python_check_callback(self, _loop, watcher_ptr, _events):
pass
......
......@@ -14,6 +14,7 @@ libev = _corecffi.lib # pylint:disable=no-member
if hasattr(libev, 'vfd_open'):
# Must be on windows
# pylint:disable=c-extension-no-member
assert sys.platform.startswith("win"), "vfd functions only needed on windows"
vfd_open = libev.vfd_open
vfd_free = libev.vfd_free
......
......@@ -47,10 +47,6 @@ class _Callbacks(AbstractCallbacks):
the_watcher.loop._queue_callback(watcher_ptr, revents)
def __loop_from_loop_ptr(self, loop_ptr):
loop_handle = loop_ptr.data
return self.from_handle(loop_handle)
_callbacks = assign_standard_callbacks(
ffi, libuv, _Callbacks,
......@@ -116,7 +112,6 @@ class loop(AbstractLoop):
def __init__(self, flags=None, default=None):
AbstractLoop.__init__(self, ffi, libuv, _watchers, flags, default)
self.__loop_pid = os.getpid()
self._child_watchers = defaultdict(list)
self._io_watchers = dict()
self._fork_watchers = set()
......
......@@ -164,7 +164,7 @@ class AbstractResolver(object):
# behaviour with special names. Notably, ``gethostbyname`` will handle
# both "<broadcast>" and "255.255.255.255", while ``gethostbyname_ex`` refuses to
# handle those; they result in different errors, too. So we can't
# pass those throgh.
# pass those through.
hostname = self._hostname_to_bytes(hostname)
if hostname in self._LOCAL_AND_BROADCAST_HOSTNAMES:
return native_gethostbyname(hostname)
......
......@@ -242,6 +242,7 @@ class Resolver(AbstractResolver):
(SOCK_DGRAM, SOL_UDP),
]
# pylint:disable=not-an-iterable,unsubscriptable-object
result = [
(rfamily,
hard_type if not rtype else rtype,
......@@ -275,6 +276,7 @@ class Resolver(AbstractResolver):
proto=0, flags=0)
if not result:
raise
# pylint:disable=unsubscriptable-object
_ip_address = result[0][-1][0]
if isinstance(_ip_address, text_type):
_ip_address = _ip_address.encode('ascii')
......
......@@ -70,10 +70,11 @@ test_name = os.path.splitext(test_filename)[0]
# string. Passing unicode to `compile` on Python 2 can
# do bad things: it conflicts with a 'coding:' directive,
# and it can cause some TypeError with string literals
# We do use with; just not on the same line!
if sys.version_info[0] >= 3:
module_file = open(test_filename, encoding='utf-8')
module_file = open(test_filename, encoding='utf-8') # pylint:disable=consider-using-with
else:
module_file = open(test_filename)
module_file = open(test_filename) # pylint:disable=consider-using-with
with module_file:
module_source = module_file.read()
module_source = disable_tests_in_source(module_source, test_name)
......
......@@ -274,7 +274,8 @@ class TestCase(TestCaseMetaClass("NewBase",
error_fatal = True
uses_handle_error = True
close_on_teardown = ()
__old_subscribers = ()
# This is really used by the SubscriberCleanupMixin
__old_subscribers = () # pylint:disable=unused-private-member
def run(self, *args, **kwargs): # pylint:disable=signature-differs
if self.switch_expected == 'default':
......
......@@ -327,6 +327,7 @@ class ConditionTests(BaseTestCase):
cond = self.condtype()
# Be default we have an RLock: the condition can be acquired multiple
# times.
# pylint:disable=consider-using-with
cond.acquire()
cond.acquire()
cond.release()
......
......@@ -9,7 +9,7 @@ from __future__ import absolute_import
import dns
assert dns
import gevent.socket as socket
import gevent.socket as socket # pylint:disable=consider-using-from-import
socket.getfqdn() # create the resolver
from gevent.resolver.dnspython import dns as gdns
......
......@@ -341,8 +341,8 @@ class TestPeriodicMonitorMemory(_AbstractTestPeriodicMonitoringThread,
event = self.pmt.monitor_memory_usage(None)
self.assertIsInstance(event, events.MemoryUsageThresholdExceeded)
self.assertEqual(2, event.mem_usage)
self.assertEqual(1, event.max_allowed)
self.assertIsInstance(event.memory_info, MockProcess)
self.assertEqual(1, event.max_allowed) # pylint:disable=no-member
self.assertIsInstance(event.memory_info, MockProcess) # pylint:disable=no-member
# No growth, no event
event = self.pmt.monitor_memory_usage(None)
......
......@@ -370,11 +370,9 @@ class ContextTest(unittest.TestCase):
self.assertEqual(cvar.get(), num + i)
return num
tp = concurrent.futures.ThreadPoolExecutor(max_workers=10)
try:
with concurrent.futures.ThreadPoolExecutor(max_workers=10) as tp:
results = list(tp.map(sub, range(10)))
finally:
tp.shutdown()
self.assertEqual(results, list(range(10)))
# gevent: clases's can't be subscripted on Python 3.6
......
......@@ -6,6 +6,7 @@ import subprocess
if sys.argv[1:] == []:
os.environ['GEVENT_BACKEND'] = 'select'
# (not in Py2) pylint:disable=consider-using-with
popen = subprocess.Popen([sys.executable, __file__, '1'])
assert popen.wait() == 0, popen.poll()
else: # pragma: no cover
......
......@@ -62,7 +62,7 @@ class Test_wsgiserver(util.TestServer):
sock = socket.create_connection((params.DEFAULT_LOCAL_HOST_ADDR, self.PORT))
ssl_sock = None
if self._use_ssl:
ssl_sock = ssl.wrap_socket(sock)
ssl_sock = ssl.wrap_socket(sock) # pylint:disable=deprecated-method
sock_file = ssl_sock.makefile(mode='rwb')
else:
sock_file = sock.makefile(mode='rwb')
......
......@@ -3,5 +3,5 @@
# attempts to import encodings.idna but blocks on the import lock. Verify
# that gevent avoids this deadlock.
import getaddrinfo_module
import getaddrinfo_module # pylint:disable=import-error
del getaddrinfo_module # fix pyflakes
......@@ -2,6 +2,6 @@
from gevent import monkey
monkey.patch_all()
import _import_wait
import _import_wait # pylint:disable=import-error
assert _import_wait.x
......@@ -6,6 +6,7 @@ import sys
if not sys.argv[1:]:
from subprocess import Popen, PIPE
# not on Py2 pylint:disable=consider-using-with
p = Popen([sys.executable, __file__, 'subprocess'], stdin=PIPE, stdout=PIPE, stderr=PIPE)
out, err = p.communicate(b'hello world\n')
code = p.poll()
......
......@@ -26,7 +26,7 @@ class TestIssue600(greentest.TestCase):
# Run a subprocess through Popen to make sure
# libev is handling SIGCHLD. This could *probably* be simplified to use
# just hub.loop.install_sigchld
# (no __enter__/__exit__ on Py2) pylint:disable=consider-using-with
p = Popen([sys.executable, '-V'], stdout=PIPE, stderr=PIPE)
gevent.sleep(0)
p.communicate()
......
......@@ -45,6 +45,7 @@ else:
kwargs = {'creationflags': CREATE_NEW_PROCESS_GROUP}
else:
kwargs = {}
# (not on Py2) pylint:disable=consider-using-with
p = Popen([sys.executable, __file__, 'subprocess'], stdout=PIPE, **kwargs)
line = p.stdout.readline()
if not isinstance(line, str):
......
......@@ -12,7 +12,7 @@ from zope import interface
try:
from collections.abc import Mapping
except ImportError:
from collections import Mapping
from collections import Mapping # pylint:disable=deprecated-class
class ReadProperty(object):
"""A property that can be overridden"""
......@@ -72,7 +72,7 @@ class WithGetattr(local):
def __getattr__(self, name):
if name == 'foo':
return 42
return super(WithGetattr, self).__getattr__(name)
return super(WithGetattr, self).__getattr__(name) # pylint:disable=no-member
class LocalWithABC(local, Mapping):
......@@ -263,7 +263,7 @@ class TestGeventLocal(greentest.TestCase):
mylocal.CLASS_PROP = 1
self.assertEqual(1, mylocal.CLASS_PROP)
self.assertEqual(mylocal.__dict__['CLASS_PROP'], 1)
self.assertEqual(mylocal.__dict__['CLASS_PROP'], 1) # pylint:disable=unsubscriptable-object
del mylocal.CLASS_PROP
self.assertEqual(42, mylocal.CLASS_PROP)
......
......@@ -33,6 +33,8 @@ try:
except ImportError:
psutil = None
# wrap_socket() is considered deprecated in 3.9
# pylint:disable=deprecated-method
class Test(greentest.TestCase):
......
......@@ -70,10 +70,10 @@ class TestMonkey(SubscriberCleanupMixin, unittest.TestCase):
def test_saved(self):
self.assertTrue(monkey.saved)
for modname in monkey.saved:
for modname, objects in monkey.saved.items():
self.assertTrue(monkey.is_module_patched(modname))
for objname in monkey.saved[modname]:
for objname in objects:
self.assertTrue(monkey.is_object_patched(modname, objname))
def test_patch_subprocess_twice(self):
......
......@@ -45,6 +45,7 @@ if hasattr(signal, 'SIGCHLD'):
# Go through subprocess because we expect it to automatically
# set up the waiting for us.
# not on Py2 pylint:disable=consider-using-with
popen = subprocess.Popen([sys.executable, '-c', 'import sys'],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
popen.stderr.read()
......
......@@ -315,7 +315,7 @@ class TestCase(greentest.TestCase):
def urlopen(self, *args, **kwargs):
with self.connect() as sock:
with sock.makefile(bufsize=1) as fd:
with sock.makefile(bufsize=1) as fd: # pylint:disable=unexpected-keyword-arg
fd.write('GET / HTTP/1.1\r\nHost: localhost\r\n\r\n')
return read_http(fd, *args, **kwargs)
......@@ -857,7 +857,7 @@ class HttpsTestCase(TestCase):
def urlopen(self, method='GET', post_body=None, **kwargs): # pylint:disable=arguments-differ
import ssl
with self.connect() as raw_sock:
with ssl.wrap_socket(raw_sock) as sock:
with ssl.wrap_socket(raw_sock) as sock: # pylint:disable=deprecated-method
with sock.makefile(bufsize=1) as fd: # pylint:disable=unexpected-keyword-arg
fd.write('%s / HTTP/1.1\r\nHost: localhost\r\n' % method)
if post_body is not None:
......@@ -1632,10 +1632,10 @@ class TestInputRaw(greentest.BaseTestCase):
return Input(StringIO(data), content_length=content_length, chunked_input=chunked_input)
if PY3:
def assertEqual(self, data, expected, *args): # pylint:disable=arguments-differ
if isinstance(expected, str):
expected = expected.encode('ascii')
super(TestInputRaw, self).assertEqual(data, expected, *args)
def assertEqual(self, first, second, msg=None):
if isinstance(second, str):
second = second.encode('ascii')
super(TestInputRaw, self).assertEqual(first, second, msg)
def test_short_post(self):
i = self.make_input("1", content_length=2)
......
......@@ -98,7 +98,7 @@ class Server(object):
self.listening = True
try:
conn, _ = self.socket.accept()
conn, _ = self.socket.accept() # pylint:disable=no-member
except socket.timeout:
if self.raise_on_timeout:
raise
......
......@@ -33,6 +33,9 @@ from threading import Event
errno_types = int
# socket.accept/unwrap/makefile aren't found for some reason
# pylint:disable=no-member
class BaseThread(object):
terminal_exc = None
......
......@@ -15,6 +15,7 @@ from gevent.testing import PY2
def ssl_listener(private_key, certificate):
raw_listener = socket.socket()
greentest.bind_and_listen(raw_listener)
# pylint:disable=deprecated-method
sock = ssl.wrap_socket(raw_listener, private_key, certificate, server_side=True)
return sock, raw_listener
......@@ -40,6 +41,7 @@ class TestSSL(test__socket.TestTCP):
def create_connection(self, *args, **kwargs): # pylint:disable=signature-differs
return self._close_on_teardown(
# pylint:disable=deprecated-method
ssl.wrap_socket(super(TestSSL, self).create_connection(*args, **kwargs)))
# The SSL library can take a long time to buffer the large amount of data we're trying
......@@ -67,7 +69,9 @@ class TestSSL(test__socket.TestTCP):
# Issue #317: SSL_WRITE_PENDING in some corner cases
server_sock = []
acceptor = test__socket.Thread(target=lambda: server_sock.append(self.listener.accept()))
acceptor = test__socket.Thread(target=lambda: server_sock.append(
# pylint:disable=no-member
self.listener.accept()))
client = self.create_connection()
client.setblocking(False)
try:
......
......@@ -15,6 +15,7 @@ else:
import subprocess
for _ in range(5):
# not on Py2 pylint:disable=consider-using-with
out, err = subprocess.Popen([sys.executable, '-W', 'ignore',
__file__, 'runtestcase'],
stderr=subprocess.PIPE).communicate()
......
......@@ -59,6 +59,7 @@ class TestLockThread(greentest.TestCase):
def test_spin_lock_switches(self):
# https://github.com/gevent/gevent/issues/1464
# pylint:disable=consider-using-with
lock = threading.Lock()
lock.acquire()
spawned = []
......
......@@ -45,6 +45,8 @@ import weakref
from gevent.tests import lock_tests
verbose = False
# pylint:disable=consider-using-with
# A trivial mutable counter.
def skipDueToHang(cls):
......
......@@ -143,6 +143,7 @@ class _DummyThread(_DummyThread_):
ref = self.__weakref_ref
ref = ref(g, _make_cleanup_id(gid)) # pylint:disable=too-many-function-args
self.__raw_ref = ref
assert self.__raw_ref is ref # prevent pylint thinking its unused
def _Thread__stop(self):
pass
......
......@@ -552,7 +552,7 @@ class _FakeAsync(object):
pass
close = stop = send
def __call_(self, result):
def __call__(self, result):
"fake out for 'receiver'"
def __bool__(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment