Skip to content

Commit

Permalink
Compatibility with pylint 1.7
Browse files Browse the repository at this point in the history
  • Loading branch information
jamadden committed May 11, 2017
1 parent 52f5022 commit 4f26715
Show file tree
Hide file tree
Showing 33 changed files with 98 additions and 103 deletions.
7 changes: 5 additions & 2 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 11 additions & 2 deletions src/gevent/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,18 @@ def __new__(cls, *args, **kwargs):

# 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
Expand Down
7 changes: 3 additions & 4 deletions src/gevent/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
## Types

if PY3:
string_types = str,
integer_types = int,
string_types = (str,)
integer_types = (int,)
text_type = str

else:
Expand All @@ -42,8 +42,7 @@ def reraise(t, value, tb=None): # pylint:disable=unused-argument
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
2 changes: 1 addition & 1 deletion src/gevent/_fileobjectcommon.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def close(self):
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):
Expand Down
11 changes: 3 additions & 8 deletions src/gevent/_fileobjectposix.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,16 +269,11 @@ def __init__(self, fobj, mode='rb', bufsize=-1, close=True):
# 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()
Expand Down
5 changes: 2 additions & 3 deletions src/gevent/_socket3.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ def type(self):
# 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
Expand Down Expand Up @@ -227,7 +226,7 @@ def makefile(self, mode="r", buffering=None, *,
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)
Expand Down
4 changes: 2 additions & 2 deletions src/gevent/_socketcommon.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@

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)

Expand Down Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions src/gevent/_ssl2.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ def getpeercert(self, binary_form=False):
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:
Expand Down Expand Up @@ -253,8 +252,7 @@ def recvfrom_into(self, *args):
def pending(self):
if self._sslobj:
return self._sslobj.pending()
else:
return 0
return 0

def _sslobj_shutdown(self):
while True:
Expand Down
26 changes: 11 additions & 15 deletions src/gevent/_ssl3.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ def wrap_socket(self, sock, server_side=False,
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,
Expand All @@ -67,6 +69,7 @@ def wrap_socket(self, sock, server_side=False,
# 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)
Expand Down Expand Up @@ -287,8 +290,7 @@ def read(self, len=1024, buffer=None):
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
Expand All @@ -302,8 +304,7 @@ def read(self, len=1024, buffer=None):
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

Expand Down Expand Up @@ -350,17 +351,15 @@ def selected_npn_protocol(self):
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+
def selected_alpn_protocol(self):
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
Expand All @@ -381,15 +380,13 @@ 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 send(self, data, flags=0, timeout=timeout_default):
self._checkClosed()
Expand Down Expand Up @@ -502,8 +499,7 @@ def pending(self):
self._checkClosed()
if self._sslobj:
return self._sslobj.pending()
else:
return 0
return 0

def shutdown(self, how):
self._checkClosed()
Expand Down
21 changes: 7 additions & 14 deletions src/gevent/_sslgte279.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,7 @@ def read(self, len=1024, buffer=None):
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
Expand All @@ -326,8 +325,7 @@ def read(self, len=1024, buffer=None):
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

Expand Down Expand Up @@ -368,31 +366,27 @@ def selected_npn_protocol(self):
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+
def selected_alpn_protocol(self):
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:
Expand Down Expand Up @@ -510,8 +504,7 @@ def pending(self):
self._checkClosed()
if self._sslobj:
return self._sslobj.pending()
else:
return 0
return 0

def shutdown(self, how):
self._checkClosed()
Expand Down
3 changes: 2 additions & 1 deletion src/gevent/_tblib.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- 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.
Expand Down Expand Up @@ -116,7 +117,7 @@ def tb_set_next(tb, next):
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>.+))?$')
Expand Down
3 changes: 1 addition & 2 deletions src/gevent/_threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ def _is_owned(self):
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():
Expand Down
1 change: 0 additions & 1 deletion src/gevent/_util_py2.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# this produces syntax error on Python3


__all__ = ['reraise']


Expand Down
3 changes: 2 additions & 1 deletion src/gevent/backdoor.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def switch_out(self):
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)
Expand Down Expand Up @@ -147,7 +148,7 @@ def handle(self, conn, _address): # pylint: disable=method-hidden
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()
Expand Down
2 changes: 1 addition & 1 deletion src/gevent/baseserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
2 changes: 1 addition & 1 deletion src/gevent/builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/gevent/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@

copy_globals(_core, globals())

__all__ = _core.__all__
__all__ = _core.__all__ # pylint:disable=no-member
Loading

0 comments on commit 4f26715

Please sign in to comment.