Commit 4f267154 authored by Jason Madden's avatar Jason Madden

Compatibility with pylint 1.7

parent 52f5022a
......@@ -28,6 +28,7 @@
# see https://github.com/PyCQA/pylint/issues/846
# useless-suppression: the only way to avoid repeating it for specific statements everywhere that we
# do Py2/Py3 stuff is to put it here. Sadly this means that we might get better but not realize it.
# duplicate-code: Yeah, the compatibility ssl modules are much the same
disable=wrong-import-position,
wrong-import-order,
missing-docstring,
......@@ -44,12 +45,14 @@ disable=wrong-import-position,
too-many-arguments,
redefined-builtin,
useless-suppression,
# undefined-all-variable
duplicate-code,
undefined-all-variable
[FORMAT]
# duplicated from setup.cfg
max-line-length=160
max-module-lines=1070
[MISCELLANEOUS]
# List of note tags to take in consideration, separated by a comma.
......@@ -80,7 +83,7 @@ ignored-classes=SSLContext, SSLSocket, greenlet, Greenlet, parent, dead
# (useful for modules/projects where namespaces are manipulated during runtime
# and thus existing member attributes cannot be deduced by static analysis. It
# supports qualified module names, as well as Unix pattern matching.
ignored-modules=gevent._corecffi
ignored-modules=gevent._corecffi,gevent.os,os,greenlet,threading,gevent.libev.corecffi
[DESIGN]
max-attributes=12
......
......@@ -2,6 +2,7 @@ setuptools
wheel
cython>=0.25.1
greenlet>=0.4.10
pylint>=1.7.1
prospector[with_pyroma]
coverage>=4.0
coveralls>=1.0
......
......@@ -117,9 +117,18 @@ del sys
# the following makes hidden imports visible to freezing tools like
# py2exe. see https://github.com/gevent/gevent/issues/181
def __dependencies_for_freezing():
from gevent import core, resolver_thread, resolver_ares, socket as _socket,\
threadpool, thread, threading, select, subprocess
# pylint:disable=unused-variable
from gevent import core
from gevent import resolver_thread
from gevent import resolver_ares
from gevent import socket as _socket
from gevent import threadpool
from gevent import thread
from gevent import threading
from gevent import select
from gevent import subprocess
import pprint
import traceback
import signal as _signal
......
......@@ -15,8 +15,8 @@ PYPY = hasattr(sys, 'pypy_version_info')
## Types
if PY3:
string_types = str,
integer_types = int,
string_types = (str,)
integer_types = (int,)
text_type = str
else:
......@@ -42,8 +42,7 @@ if PY3:
iteritems = dict.items
itervalues = dict.values
xrange = range
else:
iteritems = dict.iteritems # python 3: pylint:disable=no-member
itervalues = dict.itervalues # python 3: pylint:disable=no-member
xrange = __builtin__.xrange # python 2: pylint:disable=redefined-variable-type
xrange = __builtin__.xrange
......@@ -113,7 +113,7 @@ class FileObjectBase(object):
self._io = None
self._do_close(io, self._close)
def _do_close(self, io, closefd):
def _do_close(self, fobj, closefd):
raise NotImplementedError()
def __getattr__(self, name):
......
......@@ -269,16 +269,11 @@ class FileObjectPosix(FileObjectBase):
# attribute.
IOFamily = FlushingBufferedWriter
io = IOFamily(self.fileio, bufsize)
#else: # QQQ: not used, not reachable
#
# self.io = BufferedRandom(self.fileio, bufsize)
super(FileObjectPosix, self).__init__(IOFamily(self.fileio, bufsize), close)
super(FileObjectPosix, self).__init__(io, close)
def _do_close(self, io, closefd):
def _do_close(self, fobj, closefd):
try:
io.close()
fobj.close()
# self.fileio already knows whether or not to close the
# file descriptor
self.fileio.close()
......
......@@ -99,8 +99,7 @@ class socket(object):
# See https://github.com/gevent/gevent/pull/399
if self.timeout != 0.0:
return self._sock.type & ~_socket.SOCK_NONBLOCK # pylint:disable=no-member
else:
return self._sock.type
return self._sock.type
def __enter__(self):
return self
......@@ -227,7 +226,7 @@ class socket(object):
if reading and writing:
buffer = io.BufferedRWPair(raw, raw, buffering)
elif reading:
buffer = io.BufferedReader(raw, buffering) # pylint:disable=redefined-variable-type
buffer = io.BufferedReader(raw, buffering)
else:
assert writing
buffer = io.BufferedWriter(raw, buffering)
......
......@@ -113,7 +113,7 @@ __imports__ = copy_globals(__socket__, globals(),
for _name in __socket__.__all__:
_value = getattr(__socket__, _name)
if isinstance(_value, integer_types) or isinstance(_value, string_types):
if isinstance(_value, (integer_types, string_types)):
globals()[_name] = _value
__imports__.append(_name)
......@@ -332,7 +332,7 @@ def getfqdn(name=''):
pass
else:
aliases.insert(0, hostname)
for name in aliases:
for name in aliases: # EWW! pylint:disable=redefined-argument-from-local
if isinstance(name, bytes):
if b'.' in name:
break
......
......@@ -146,8 +146,7 @@ class SSLSocket(socket):
def cipher(self):
if not self._sslobj:
return None
else:
return self._sslobj.cipher()
return self._sslobj.cipher()
def send(self, data, flags=0, timeout=timeout_default):
if timeout is timeout_default:
......@@ -253,8 +252,7 @@ class SSLSocket(socket):
def pending(self):
if self._sslobj:
return self._sslobj.pending()
else:
return 0
return 0
def _sslobj_shutdown(self):
while True:
......
......@@ -48,7 +48,9 @@ class SSLContext(orig_SSLContext):
do_handshake_on_connect=True,
suppress_ragged_eofs=True,
server_hostname=None,
session=None): # 3.6
session=None):
# pylint:disable=arguments-differ
# (3.6 adds session)
# Sadly, using *args and **kwargs doesn't work
return SSLSocket(sock=sock, server_side=server_side,
do_handshake_on_connect=do_handshake_on_connect,
......@@ -67,6 +69,7 @@ class SSLContext(orig_SSLContext):
# super(SSLContext, SSLContext). But we rebind SSLContext when we monkey
# patch, which causes infinite recursion.
# https://github.com/python/cpython/commit/328067c468f82e4ec1b5c510a4e84509e010f296
# pylint:disable=no-member
@orig_SSLContext.options.setter
def options(self, value):
super(orig_SSLContext, orig_SSLContext).options.__set__(self, value)
......@@ -287,8 +290,7 @@ class SSLSocket(socket):
try:
if buffer is not None:
return self._sslobj.read(len, buffer)
else:
return self._sslobj.read(len or 1024)
return self._sslobj.read(len or 1024)
except SSLWantReadError:
if self.timeout == 0.0:
raise
......@@ -302,8 +304,7 @@ class SSLSocket(socket):
if ex.args[0] == SSL_ERROR_EOF and self.suppress_ragged_eofs:
if buffer is None:
return b''
else:
return 0
return 0
else:
raise
......@@ -350,8 +351,7 @@ class SSLSocket(socket):
self._checkClosed()
if not self._sslobj or not _ssl.HAS_NPN:
return None
else:
return self._sslobj.selected_npn_protocol()
return self._sslobj.selected_npn_protocol()
if hasattr(_ssl, 'HAS_ALPN'):
# 3.5+
......@@ -359,8 +359,7 @@ class SSLSocket(socket):
self._checkClosed()
if not self._sslobj or not _ssl.HAS_ALPN: # pylint:disable=no-member
return None
else:
return self._sslobj.selected_alpn_protocol()
return self._sslobj.selected_alpn_protocol()
def shared_ciphers(self):
"""Return a list of ciphers shared by the client during the handshake or
......@@ -381,15 +380,13 @@ class SSLSocket(socket):
self._checkClosed()
if not self._sslobj:
return None
else:
return self._sslobj.cipher()
return self._sslobj.cipher()
def compression(self):
self._checkClosed()
if not self._sslobj:
return None
else:
return self._sslobj.compression()
return self._sslobj.compression()
def send(self, data, flags=0, timeout=timeout_default):
self._checkClosed()
......@@ -502,8 +499,7 @@ class SSLSocket(socket):
self._checkClosed()
if self._sslobj:
return self._sslobj.pending()
else:
return 0
return 0
def shutdown(self, how):
self._checkClosed()
......
......@@ -311,8 +311,7 @@ class SSLSocket(socket):
try:
if buffer is not None:
return self._sslobj.read(len, buffer)
else:
return self._sslobj.read(len or 1024)
return self._sslobj.read(len or 1024)
except SSLWantReadError:
if self.timeout == 0.0:
raise
......@@ -326,8 +325,7 @@ class SSLSocket(socket):
if ex.args[0] == SSL_ERROR_EOF and self.suppress_ragged_eofs:
if buffer is not None:
return 0
else:
return b''
return b''
else:
raise
......@@ -368,8 +366,7 @@ class SSLSocket(socket):
self._checkClosed()
if not self._sslobj or not _ssl.HAS_NPN:
return None
else:
return self._sslobj.selected_npn_protocol()
return self._sslobj.selected_npn_protocol()
if hasattr(_ssl, 'HAS_ALPN'):
# 2.7.10+
......@@ -377,22 +374,19 @@ class SSLSocket(socket):
self._checkClosed()
if not self._sslobj or not _ssl.HAS_ALPN: # pylint:disable=no-member
return None
else:
return self._sslobj.selected_alpn_protocol()
return self._sslobj.selected_alpn_protocol()
def cipher(self):
self._checkClosed()
if not self._sslobj:
return None
else:
return self._sslobj.cipher()
return self._sslobj.cipher()
def compression(self):
self._checkClosed()
if not self._sslobj:
return None
else:
return self._sslobj.compression()
return self._sslobj.compression()
def __check_flags(self, meth, flags):
if flags != 0:
......@@ -510,8 +504,7 @@ class SSLSocket(socket):
self._checkClosed()
if self._sslobj:
return self._sslobj.pending()
else:
return 0
return 0
def shutdown(self, how):
self._checkClosed()
......
# -*- coding: utf-8 -*-
# A vendored version of part of https://github.com/ionelmc/python-tblib
# pylint:disable=redefined-outer-name,reimported,function-redefined,bare-except,no-else-return,broad-except
####
# Copyright (c) 2013-2016, Ionel Cristian Mărieș
# All rights reserved.
......@@ -116,7 +117,7 @@ except ImportError:
tproxy = None
__version__ = '1.3.0'
__all__ = 'Traceback',
__all__ = ('Traceback',)
PY3 = sys.version_info[0] == 3
FRAME_RE = re.compile(r'^\s*File "(?P<co_filename>.+)", line (?P<tb_lineno>\d+)(, in (?P<co_name>.+))?$')
......
......@@ -138,8 +138,7 @@ class Condition(object):
if self.__lock.acquire(0):
self.__lock.release()
return False
else:
return True
return True
def wait(self, timeout=None):
if not self._is_owned():
......
# this produces syntax error on Python3
__all__ = ['reraise']
......
......@@ -48,6 +48,7 @@ class _Greenlet_stdreplace(Greenlet):
self.saved = None
def throw(self, *args, **kwargs):
# pylint:disable=arguments-differ
if self.saved is None and self._fileobj is not None:
self.switch_in()
Greenlet.throw(self, *args, **kwargs)
......@@ -147,7 +148,7 @@ class BackdoorServer(StreamServer):
if sys.version_info[:3] >= (3, 6, 0):
# Beginning in 3.6, the console likes to print "now exiting <class>"
# but probably our socket is already closed, so this just causes problems.
console.interact(banner=self.banner, exitmsg='')
console.interact(banner=self.banner, exitmsg='') # pylint:disable=unexpected-keyword-arg
else:
console.interact(banner=self.banner)
except SystemExit: # raised by quit()
......
......@@ -381,7 +381,7 @@ def _parse_address(address):
return _socket.AF_INET, address
if ((isinstance(address, string_types) and ':' not in address)
or isinstance(address, integer_types)): # noqa (pep8 E129)
or isinstance(address, integer_types)): # noqa (pep8 E129)
# Just a port
return _socket.AF_INET6, ('', int(address))
......
......@@ -75,7 +75,7 @@ def __import__(*args, **kwargs):
wraps the normal __import__ functionality in a recursive lock, ensuring that
we're protected against greenlet import concurrency as well.
"""
if len(args) > 0 and not issubclass(type(args[0]), _allowed_module_name_types):
if args and not issubclass(type(args[0]), _allowed_module_name_types):
# if a builtin has been acquired as a bound instance method,
# python knows not to pass 'self' when the method is called.
# No such protection exists for monkey-patched builtins,
......
......@@ -19,4 +19,4 @@ except ImportError:
copy_globals(_core, globals())
__all__ = _core.__all__
__all__ = _core.__all__ # pylint:disable=no-member
......@@ -179,7 +179,7 @@ class Event(_AbstractLinkable):
"""
self._flag = False
def _wait_return_value(self, waited, gotit):
def _wait_return_value(self, waited, wait_success):
# To avoid the race condition outlined in http://bugs.python.org/issue13502,
# if we had to wait, then we need to return whether or not
# the condition got changed. Otherwise we simply echo
......@@ -189,7 +189,7 @@ class Event(_AbstractLinkable):
assert flag, "if we didn't wait we should already be set"
return flag
return gotit
return wait_success
def wait(self, timeout=None):
"""
......@@ -393,7 +393,7 @@ class AsyncResult(_AbstractLinkable):
"""
return self.get(block=False)
def _wait_return_value(self, waited, gotit):
def _wait_return_value(self, waited, wait_success):
# pylint:disable=unused-argument
# Always return the value. Since this is a one-shot event,
# no race condition should reset it.
......
......@@ -57,9 +57,11 @@ else:
return
__all__ = ['FileObjectPosix',
'FileObjectThread',
'FileObject']
__all__ = [
'FileObjectPosix',
'FileObjectThread',
'FileObject',
]
try:
from fcntl import fcntl
......@@ -104,7 +106,7 @@ class FileObjectThread(FileObjectBase):
if self.lock is True:
self.lock = Semaphore()
elif not self.lock:
self.lock = DummySemaphore() # pylint:disable=redefined-variable-type
self.lock = DummySemaphore()
if not hasattr(self.lock, '__enter__'):
raise TypeError('Expected a Semaphore or boolean, got %r' % type(self.lock))
if isinstance(fobj, integer_types):
......@@ -201,6 +203,9 @@ class FileObjectBlock(FileObjectBase):
fobj = os.fdopen(fobj, *args)
super(FileObjectBlock, self).__init__(fobj, closefd)
def _do_close(self, fobj, closefd):
fobj.close()
config = os.environ.get('GEVENT_FILE')
if config:
klass = {'thread': 'gevent.fileobject.FileObjectThread',
......
......@@ -835,10 +835,9 @@ class Waiter(object):
def __str__(self):
if self._exception is _NONE:
return '<%s greenlet=%s>' % (type(self).__name__, self.greenlet)
elif self._exception is None:
if self._exception is None:
return '<%s greenlet=%s value=%r>' % (type(self).__name__, self.greenlet, self.value)
else:
return '<%s greenlet=%s exc_info=%r>' % (type(self).__name__, self.greenlet, self.exc_info)
return '<%s greenlet=%s exc_info=%r>' % (type(self).__name__, self.greenlet, self.exc_info)
def ready(self):
"""Return true if and only if it holds a value or an exception"""
......
# pylint: disable=too-many-lines, protected-access, redefined-outer-name, not-callable
# pylint:disable=too-many-lines, protected-access, redefined-outer-name, not-callable,
from __future__ import absolute_import, print_function
import sys
import os
import traceback
import signal as signalmodule
# pylint:disable=undefined-all-variable
__all__ = [
'get_version',
'get_header_version',
......@@ -108,7 +108,7 @@ def _python_callback(handle, revents):
# Legacy behaviour from corecext: convert None into ()
# See test__core_watcher.py
args = _NOARGS
if len(args) > 0 and args[0] == GEVENT_CORE_EVENTS:
if args and args[0] == GEVENT_CORE_EVENTS:
args = (revents, ) + args[1:]
the_watcher.callback(*args)
except: # pylint:disable=bare-except
......@@ -247,7 +247,7 @@ def _flags_to_list(flags):
if sys.version_info[0] >= 3:
basestring = (bytes, str)
integer_types = int,
integer_types = (int,)
else:
import __builtin__ # pylint:disable=import-error
basestring = __builtin__.basestring,
......@@ -892,6 +892,7 @@ class io(watcher):
watcher.__init__(self, loop, ref=ref, priority=priority, args=(fd, events))
def start(self, callback, *args, **kwargs):
# pylint:disable=arguments-differ
args = args or _NOARGS
if kwargs.get('pass_events'):
args = (GEVENT_CORE_EVENTS, ) + args
......@@ -936,6 +937,7 @@ class timer(watcher):
watcher.__init__(self, loop, ref=ref, priority=priority, args=(after, repeat))
def start(self, callback, *args, **kw):
# pylint:disable=arguments-differ
update = kw.get("update", True)
if update:
# Quoth the libev doc: "This is a costly operation and is
......
......@@ -78,11 +78,11 @@ __all__ = [
if sys.version_info[0] >= 3:
string_types = str,
string_types = (str,)
PY3 = True
else:
import __builtin__ # pylint:disable=import-error
string_types = __builtin__.basestring,
string_types = (__builtin__.basestring,)
PY3 = False
WIN = sys.platform.startswith("win")
......@@ -128,8 +128,7 @@ def get_original(mod_name, item_name):
"""
if isinstance(item_name, string_types):
return _get_original(mod_name, [item_name])[0]
else:
return _get_original(mod_name, item_name)
return _get_original(mod_name, item_name)
_NONE = object()
......@@ -407,8 +406,6 @@ def patch_thread(threading=True, _threading_local=True, Event=False, logging=Tru
if orig_current_thread == threading_mod.main_thread():
main_thread = threading_mod.main_thread()
_greenlet = main_thread._greenlet = greenlet.getcurrent()
from gevent.hub import sleep
main_thread.join = make_join_func(main_thread, _greenlet)
......
......@@ -322,8 +322,7 @@ class GroupMappingMixin(object):
kwds = {}
if self._apply_immediately():
return func(*args, **kwds)
else:
return self.spawn(func, *args, **kwds).get()
return self.spawn(func, *args, **kwds).get()
def map(self, func, iterable):
"""Return a list made by applying the *func* to each element of
......
......@@ -317,8 +317,7 @@ class Input(object):
def readline(self, size=None):
if self.chunked_input:
return self._chunked_read(size, True)
else:
return self._do_read(size, use_readline=True)
return self._do_read(size, use_readline=True)
def readlines(self, hint=None):
# pylint:disable=unused-argument
......@@ -1465,7 +1464,7 @@ class WSGIServer(StreamServer):
except socket.error:
name = str(address[0])
if PY3 and not isinstance(name, str):
name = name.decode('ascii') # python 2 pylint:disable=redefined-variable-type
name = name.decode('ascii')
self.environ['SERVER_NAME'] = name
self.environ.setdefault('SERVER_PORT', str(address[1]))
else:
......
......@@ -139,8 +139,7 @@ class Queue(object):
result.append('putters[%s]' % len(self.putters))
if result:
return ' ' + ' '.join(result)
else:
return ''
return ''
def qsize(self):
"""Return the size of the queue."""
......
......@@ -221,8 +221,8 @@ class Resolver(object):
if addrs.family == AF_INET:
for addr in addrs[-1]:
sockaddr = (addr, port)
for socktype, proto in socktype_proto:
result4.append((AF_INET, socktype, proto, '', sockaddr))
for socktype4, proto4 in socktype_proto:
result4.append((AF_INET, socktype4, proto4, '', sockaddr))
elif addrs.family == AF_INET6:
for addr in addrs[-1]:
if addr == '::1':
......@@ -230,8 +230,8 @@ class Resolver(object):
else:
dest = result6
sockaddr = (addr, port, 0, 0)
for socktype, proto in socktype_proto:
dest.append((AF_INET6, socktype, proto, '', sockaddr))
for socktype6, proto6 in socktype_proto:
dest.append((AF_INET6, socktype6, proto6, '', sockaddr))
# As of 2016, some platforms return IPV6 first and some do IPV4 first,
# and some might even allow configuration of which is which. For backwards
......
......@@ -166,6 +166,7 @@ class StreamServer(BaseServer):
return sockobj, address
def do_close(self, sock, *args):
# pylint:disable=arguments-differ
sock.close()
def wrap_socket_and_handle(self, client_socket, address):
......
......@@ -5,7 +5,8 @@ from gevent._compat import PY2
from gevent._util import copy_globals
# things we expect to override, here for static analysis
def wrap_socket(sock, **kwargs): # pylint:disable=unused-argument
def wrap_socket(_sock, **_kwargs):
# pylint:disable=unused-argument
raise NotImplementedError()
if PY2:
......
......@@ -29,13 +29,12 @@ from __future__ import absolute_import, print_function
# Import magic
# pylint: disable=undefined-all-variable,undefined-variable
# Most of this we inherit from the standard lib
# pylint: disable=bare-except,too-many-locals,too-many-statements,bad-builtin,attribute-defined-outside-init
# pylint: disable=bare-except,too-many-locals,too-many-statements,attribute-defined-outside-init
# pylint: disable=too-many-branches,too-many-instance-attributes
# Most of this is cross-platform
# pylint: disable=no-member,expression-not-assigned,unused-argument,unused-variable
import errno
import gc
import io
import os
import signal
import sys
......
......@@ -43,9 +43,8 @@ from gevent.local import local as _local
def get_ident(gr=None):
if gr is None:
return id(getcurrent())
else:
return id(gr)
gr = getcurrent()
return id(gr)
def start_new_thread(function, args=(), kwargs=None):
......
......@@ -119,6 +119,7 @@ class _DummyThread(_DummyThread_):
_stop = _Thread__stop # py3
def _wait_for_tstate_lock(self, *args, **kwargs):
# pylint:disable=arguments-differ
pass
if hasattr(__threading__, 'main_thread'): # py 3.4+
......@@ -202,6 +203,7 @@ if sys.version_info[:2] >= (3, 4):
self._greenlet.join(timeout=timeout)
def _wait_for_tstate_lock(self, *args, **kwargs):
# pylint:disable=arguments-differ
raise NotImplementedError()
__implements__.append('Thread')
......
......@@ -402,7 +402,7 @@ else:
# We should only be called when _waiters has
# already been accessed.
waiters = getattr(self, '_waiters')
for w in waiters:
for w in waiters: # pylint:disable=not-an-iterable
if self.successful():
w.add_result(self)
else:
......@@ -475,7 +475,7 @@ else:
self._threadpool._destroy_worker_hub = True
def submit(self, fn, *args, **kwargs):
with self._shutdown_lock:
with self._shutdown_lock: # pylint:disable=not-context-manager
if self._shutdown:
raise RuntimeError('cannot schedule new futures after shutdown')
......@@ -486,7 +486,7 @@ else:
super(ThreadPoolExecutor, self).shutdown(wait)
# XXX: We don't implement wait properly
kill = getattr(self._threadpool, 'kill', None)
if kill:
if kill: # pylint:disable=using-constant-test
self._threadpool.kill()
self._threadpool = None
......
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