Commit 1a55d53e authored by Jason Madden's avatar Jason Madden

Lint.

parent c5f76bef
...@@ -223,20 +223,15 @@ jobs: ...@@ -223,20 +223,15 @@ jobs:
python -c 'import gevent.core; print(gevent.core.loop)' python -c 'import gevent.core; print(gevent.core.loop)'
python -c 'import gevent.ares; print(gevent.ares)' python -c 'import gevent.ares; print(gevent.ares)'
ccache -s ccache -s
# Lint disabled while I get the build back in shape.
# - name: Lint (Python 3) - name: Lint
# if: matrix.python-version == '3.10' && startsWith(runner.os, 'Linux') if: matrix.python-version == '3.11' && startsWith(runner.os, 'Linux')
# # We only need to do this on one version, and it should be Python 3, because # We only need to do this on one version.
# # pylint has stopped updating for Python 2. # We do this here rather than a separate job to avoid the compilation overhead.
# # We do this here rather than a separate job to avoid the compilation overhead. # TODO: Revisit this when we have caching of that part.
# # TODO: Revisit this when we have caching of that part. run: |
# # astroid 2.12.10 and pylint 2.15.3 encounter infinite pip install -U pylint
# # recursion in gevent/_ssl3.py on CI; I can't reproduce python -m pylint --rcfile=.pylintrc gevent
# # locally on my Mac. Trying some different version pins to see
# # what we get
# run: |
# pip install -U 'pylint<2.15'
# python -m pylint --rcfile=.pylintrc gevent
- name: "Tests: Basic" - name: "Tests: Basic"
run: | run: |
python -m gevent.tests --second-chance $G_USE_COV python -m gevent.tests --second-chance $G_USE_COV
......
[MAIN]
load-plugins=pylint.extensions.bad_builtin
[MASTER] [MASTER]
load-plugins=pylint.extensions.bad_builtin,
pylint.extensions.code_style,
pylint.extensions.dict_init_mutate,
pylint.extensions.dunder,
pylint.extensions.emptystring,
pylint.extensions.comparison_placement,
pylint.extensions.confusing_elif,
pylint.extensions.for_any_all,
pylint.extensions.consider_refactoring_into_while_condition,
pylint.extensions.check_elif,
pylint.extensions.eq_without_hash,
pylint.extensions.overlapping_exceptions,
# pylint.extensions.comparetozero,
# Takes out ``if x == 0:`` and wants you to write ``if not x:``
# but in many cases, the == 0 is actually much more clear.
# pylint.extensions.mccabe,
# We have too many too-complex methods. We should enable this and fix them
# one by one.
# pylint.extensions.redefined_variable_type,
# We use that pattern during initialization.
# magic_value wants you to not use arbitrary strings and numbers
# inline in the code. But it's overzealous and has way too many false
# positives. Trust people to do the most readable thing.
# pylint.extensions.magic_value
# Empty comment would be good, except it detects blank lines within
# a single comment block.
#
# Those are often used to separate paragraphs, like here.
# pylint.extensions.empty_comment,
# consider_ternary_expression is a nice check, but is also overzealous.
# Trust the human to do the readable thing.
# pylint.extensions.consider_ternary_expression,
# redefined_loop_name tends to catch us with things like
# for name in (a, b, c): name = name + '_column' ...
# pylint.extensions.redefined_loop_name,
# This wants you to turn ``x in (1, 2)`` into ``x in {1, 2}``.
# They both result in the LOAD_CONST bytecode, one a tuple one a
# frozenset. In theory a set lookup using hashing is faster than
# a linear scan of a tuple; but if the tuple is small, it can often
# actually be faster to scan the tuple.
# pylint.extensions.set_membership,
# Fix zope.cachedescriptors.property.Lazy; the property-classes doesn't seem to
# do anything.
# https://stackoverflow.com/questions/51160955/pylint-how-to-specify-a-self-defined-property-decorator-with-property-classes
# For releases prior to 2.14.2, this needs to be a one-line, quoted string. After that,
# a multi-line string.
# - Make zope.cachedescriptors.property.Lazy look like a property;
# fixes pylint thinking it is a method.
# - Run in Pure Python mode (ignore C extensions that respect this);
# fixes some issues with zope.interface, like IFoo.providedby(ob)
# claiming not to have the right number of parameters...except no, it does not.
init-hook =
import astroid.bases
astroid.bases.POSSIBLE_PROPERTIES.add('Lazy')
astroid.bases.POSSIBLE_PROPERTIES.add('LazyOnClass')
astroid.bases.POSSIBLE_PROPERTIES.add('readproperty')
astroid.bases.POSSIBLE_PROPERTIES.add('non_overridable')
import os
os.environ['PURE_PYTHON'] = ("1")
# Ending on a quoted string
# breaks pylint 2.14.5 (it strips the trailing quote. This is
# probably because it tries to handle one-line quoted strings as well as multi-blocks).
# The parens around it fix the issue.
extension-pkg-whitelist=gevent.greenlet,gevent.libuv._corecffi,gevent.libev._corecffi,gevent.libev._corecffi.lib,gevent.local,gevent._ident extension-pkg-whitelist=gevent.greenlet,gevent.libuv._corecffi,gevent.libev._corecffi,gevent.libev._corecffi.lib,gevent.local,gevent._ident
# Control the amount of potential inferred values when inferring a single # Control the amount of potential inferred values when inferring a single
...@@ -57,6 +127,9 @@ limit-inference-results=1 ...@@ -57,6 +127,9 @@ limit-inference-results=1
# Pylint 2.6+ adds some python-3-only things that don't apply: raise-missing-from, super-with-arguments, consider-using-f-string, redundant-u-string-prefix # Pylint 2.6+ adds some python-3-only things that don't apply: raise-missing-from, super-with-arguments, consider-using-f-string, redundant-u-string-prefix
# unnecessary-lambda-assignment: New check introduced in v2.14.0 # unnecessary-lambda-assignment: New check introduced in v2.14.0
# unnecessary-dunder-call: New check introduced in v2.14.0 # unnecessary-dunder-call: New check introduced in v2.14.0
# consider-using-assignment-expr: wants you to use the walrus operator.
# It hits way too much and its not clear they would be improvements.
# confusing-consecutive-elif: Are they though?
disable=wrong-import-position, disable=wrong-import-position,
wrong-import-order, wrong-import-order,
missing-docstring, missing-docstring,
...@@ -82,9 +155,15 @@ disable=wrong-import-position, ...@@ -82,9 +155,15 @@ disable=wrong-import-position,
raise-missing-from, raise-missing-from,
super-with-arguments, super-with-arguments,
consider-using-f-string, consider-using-f-string,
consider-using-assignment-expr,
redundant-u-string-prefix, redundant-u-string-prefix,
unnecessary-lambda-assignment, unnecessary-lambda-assignment,
unnecessary-dunder-call unnecessary-dunder-call,
use-dict-literal,
confusing-consecutive-elif,
enable=consider-using-augmented-assign
[FORMAT] [FORMAT]
# duplicated from setup.cfg # duplicated from setup.cfg
......
...@@ -116,7 +116,7 @@ if [ -d /gevent -a -d /opt/python ]; then ...@@ -116,7 +116,7 @@ if [ -d /gevent -a -d /opt/python ]; then
mkdir /gevent/wheelhouse mkdir /gevent/wheelhouse
OPATH="$PATH" OPATH="$PATH"
which auditwheel which auditwheel
for variant in `ls -d /opt/python/cp{310,27,36,37,38,39,311}*`; do for variant in `ls -d /opt/python/cp{310,38,39,311,312}*`; do
export PATH="$variant/bin:$OPATH" export PATH="$variant/bin:$OPATH"
echo "Building $variant $(python --version)" echo "Building $variant $(python --version)"
......
...@@ -390,7 +390,7 @@ class Loop(ImportableSetting, Setting): ...@@ -390,7 +390,7 @@ class Loop(ImportableSetting, Setting):
'libev-cffi', 'libev-cffi',
] ]
shortname_map = { shortname_map = { # pylint:disable=dict-init-mutate
'libev-cext': 'gevent.libev.corecext.loop', 'libev-cext': 'gevent.libev.corecext.loop',
'libev-cffi': 'gevent.libev.corecffi.loop', 'libev-cffi': 'gevent.libev.corecffi.loop',
'libuv-cffi': 'gevent.libuv.loop.loop', 'libuv-cffi': 'gevent.libuv.loop.loop',
......
...@@ -31,12 +31,11 @@ class callback(object): ...@@ -31,12 +31,11 @@ class callback(object):
# 'pending' has the same meaning as libev watchers: it is cleared before actually # 'pending' has the same meaning as libev watchers: it is cleared before actually
# running the callback # running the callback
def __nonzero__(self): def __bool__(self):
# it's nonzero if it's pending or currently executing # it's nonzero if it's pending or currently executing
# NOTE: This depends on loop._run_callbacks setting the args property # NOTE: This depends on loop._run_callbacks setting the args property
# to None. # to None.
return self.args is not None return self.args is not None
__bool__ = __nonzero__
@property @property
def pending(self): def pending(self):
......
...@@ -178,7 +178,7 @@ class AbstractCallbacks(object): ...@@ -178,7 +178,7 @@ class AbstractCallbacks(object):
# Keep it around so we can close it later. # Keep it around so we can close it later.
the_watcher.loop._keepaliveset.add(the_watcher) the_watcher.loop._keepaliveset.add(the_watcher)
return -1 return -1
else:
if (the_watcher.loop is not None if (the_watcher.loop is not None
and the_watcher in the_watcher.loop._keepaliveset and the_watcher in the_watcher.loop._keepaliveset
and the_watcher._watcher is orig_ffi_watcher): and the_watcher._watcher is orig_ffi_watcher):
......
...@@ -84,7 +84,7 @@ def events_to_str(event_field, all_events): ...@@ -84,7 +84,7 @@ def events_to_str(event_field, all_events):
c_flag = flag c_flag = flag
if event_field & c_flag: if event_field & c_flag:
result.append(string) result.append(string)
event_field = event_field & (~c_flag) event_field &= (~c_flag)
if not event_field: if not event_field:
break break
if event_field: if event_field:
......
...@@ -154,7 +154,7 @@ class GreenFileDescriptorIO(RawIOBase): ...@@ -154,7 +154,7 @@ class GreenFileDescriptorIO(RawIOBase):
while 1: while 1:
try: try:
return _read(self._fileno, n) return _read(self._fileno, n)
except (IOError, OSError) as ex: except OSError as ex:
if ex.args[0] not in ignored_errors: if ex.args[0] not in ignored_errors:
raise raise
wait_on_watcher(self._read_watcher, None, None, self.hub) wait_on_watcher(self._read_watcher, None, None, self.hub)
...@@ -192,7 +192,7 @@ class GreenFileDescriptorIO(RawIOBase): ...@@ -192,7 +192,7 @@ class GreenFileDescriptorIO(RawIOBase):
while True: while True:
try: try:
return _write(self._fileno, b) return _write(self._fileno, b)
except (IOError, OSError) as ex: except OSError as ex:
if ex.args[0] not in ignored_errors: if ex.args[0] not in ignored_errors:
raise raise
wait_on_watcher(self._write_watcher, None, None, self.hub) wait_on_watcher(self._write_watcher, None, None, self.hub)
......
...@@ -50,6 +50,9 @@ class _MonitorEntry(object): ...@@ -50,6 +50,9 @@ class _MonitorEntry(object):
def __eq__(self, other): def __eq__(self, other):
return self.function == other.function and self.period == other.period return self.function == other.function and self.period == other.period
def __hash__(self):
return hash((self.function, self.period))
def __repr__(self): def __repr__(self):
return repr((self.function, self.period, self.last_run_time)) return repr((self.function, self.period, self.last_run_time))
......
...@@ -9,7 +9,7 @@ Python 3 socket module. ...@@ -9,7 +9,7 @@ Python 3 socket module.
from __future__ import absolute_import from __future__ import absolute_import
import io import io
import os import os
import sys
from gevent import _socketcommon from gevent import _socketcommon
from gevent._util import copy_globals from gevent._util import copy_globals
...@@ -51,7 +51,7 @@ class _closedsocket(object): ...@@ -51,7 +51,7 @@ class _closedsocket(object):
detach = fileno detach = fileno
def _dummy(*args, **kwargs): # pylint:disable=no-method-argument,unused-argument def _dummy(*args, **kwargs): # pylint:disable=no-method-argument,unused-argument,no-self-argument
raise OSError(EBADF, 'Bad file descriptor') raise OSError(EBADF, 'Bad file descriptor')
# All _delegate_methods must also be initialized here. # All _delegate_methods must also be initialized here.
send = recv = recv_into = sendto = recvfrom = recvfrom_into = _dummy send = recv = recv_into = sendto = recvfrom = recvfrom_into = _dummy
...@@ -311,6 +311,7 @@ class socket(_socketcommon.SocketMixin): ...@@ -311,6 +311,7 @@ class socket(_socketcommon.SocketMixin):
# Break any reference to the loop.io objects. Our fileno, # Break any reference to the loop.io objects. Our fileno,
# which they were tied to, is about to be free to be reused, so these # which they were tied to, is about to be free to be reused, so these
# objects are no longer functional. # objects are no longer functional.
# pylint:disable-next=superfluous-parens
self._drop_events_and_close(closefd=(reason == 'closed')) self._drop_events_and_close(closefd=(reason == 'closed'))
self._sock = _closedsocket(family, type, proto, fileno, reason) self._sock = _closedsocket(family, type, proto, fileno, reason)
......
...@@ -224,6 +224,7 @@ def getaddrinfo(host, port, family=0, type=0, proto=0, flags=0): ...@@ -224,6 +224,7 @@ def getaddrinfo(host, port, family=0, type=0, proto=0, flags=0):
# function simply with integers. # function simply with integers.
addrlist = get_hub().resolver.getaddrinfo(host, port, family, type, proto, flags) addrlist = get_hub().resolver.getaddrinfo(host, port, family, type, proto, flags)
result = [ result = [
# pylint:disable=undefined-variable
(_intenum_converter(af, AddressFamily), (_intenum_converter(af, AddressFamily),
_intenum_converter(socktype, SocketKind), _intenum_converter(socktype, SocketKind),
proto, canonname, sa) proto, canonname, sa)
...@@ -527,7 +528,9 @@ class SocketMixin(object): ...@@ -527,7 +528,9 @@ class SocketMixin(object):
self.hub.cancel_wait(self._write_event, cancel_wait_ex) self.hub.cancel_wait(self._write_event, cancel_wait_ex)
self._sock.shutdown(how) self._sock.shutdown(how)
# pylint:disable-next=undefined-variable
family = property(lambda self: _intenum_converter(self._sock.family, AddressFamily)) family = property(lambda self: _intenum_converter(self._sock.family, AddressFamily))
# pylint:disable-next=undefined-variable
type = property(lambda self: _intenum_converter(self._sock.type, SocketKind)) type = property(lambda self: _intenum_converter(self._sock.type, SocketKind))
proto = property(lambda self: self._sock.proto) proto = property(lambda self: self._sock.proto)
......
...@@ -30,7 +30,7 @@ Taken verbatim from Jinja2. ...@@ -30,7 +30,7 @@ Taken verbatim from Jinja2.
https://github.com/mitsuhiko/jinja2/blob/master/jinja2/debug.py#L267 https://github.com/mitsuhiko/jinja2/blob/master/jinja2/debug.py#L267
""" """
# pylint:disable=consider-using-dict-comprehension # pylint:disable=consider-using-dict-comprehension,bad-dunder-name
#import platform # XXX: gevent cannot import platform at the top level; interferes with monkey patching #import platform # XXX: gevent cannot import platform at the top level; interferes with monkey patching
import sys import sys
......
...@@ -378,7 +378,7 @@ class Greenlet(greenlet): ...@@ -378,7 +378,7 @@ class Greenlet(greenlet):
hub = get_my_hub(self) # pylint:disable=undefined-variable hub = get_my_hub(self) # pylint:disable=undefined-variable
return hub.loop return hub.loop
def __nonzero__(self): def __nonzero__(self): # pylint:disable=bad-dunder-name
return self._start_event is not None and self._exc_info is None return self._start_event is not None and self._exc_info is None
try: try:
__bool__ = __nonzero__ # Python 3 __bool__ = __nonzero__ # Python 3
......
...@@ -116,6 +116,7 @@ class loop(AbstractLoop): ...@@ -116,6 +116,7 @@ class loop(AbstractLoop):
self._io_watchers = {} self._io_watchers = {}
self._fork_watchers = set() self._fork_watchers = set()
self._pid = os.getpid() self._pid = os.getpid()
# pylint:disable-next=superfluous-parens
self._default = (self._ptr == libuv.uv_default_loop()) self._default = (self._ptr == libuv.uv_default_loop())
self._queued_callbacks = [] self._queued_callbacks = []
......
...@@ -204,6 +204,7 @@ class watcher(_base.watcher): ...@@ -204,6 +204,7 @@ class watcher(_base.watcher):
ref = property(_get_ref, _set_ref) ref = property(_get_ref, _set_ref)
def feed(self, _revents, _callback, *_args): def feed(self, _revents, _callback, *_args):
# pylint:disable-next=broad-exception-raised
raise Exception("Not implemented") raise Exception("Not implemented")
class io(_base.IoMixin, watcher): class io(_base.IoMixin, watcher):
...@@ -602,6 +603,7 @@ class async_(_base.AsyncMixin, watcher): ...@@ -602,6 +603,7 @@ class async_(_base.AsyncMixin, watcher):
def send(self): def send(self):
assert self._callback is not async_._callback, "Sending to a closed watcher" assert self._callback is not async_._callback, "Sending to a closed watcher"
if libuv.uv_is_closing(self._watcher): if libuv.uv_is_closing(self._watcher):
# pylint:disable-next=broad-exception-raised
raise Exception("Closing handle") raise Exception("Closing handle")
libuv.uv_async_send(self._watcher) libuv.uv_async_send(self._watcher)
......
...@@ -366,7 +366,7 @@ class local(object): ...@@ -366,7 +366,7 @@ class local(object):
""" """
__slots__ = tuple(_local_attrs - {'__class__', '__cinit__'}) __slots__ = tuple(_local_attrs - {'__class__', '__cinit__'})
def __cinit__(self, *args, **kw): def __cinit__(self, *args, **kw): # pylint:disable=bad-dunder-name
if args or kw: if args or kw:
if type(self).__init__ == object.__init__: # pylint:disable=comparison-with-callable if type(self).__init__ == object.__init__: # pylint:disable=comparison-with-callable
raise TypeError("Initialization arguments are not supported", args, kw) raise TypeError("Initialization arguments are not supported", args, kw)
...@@ -600,7 +600,7 @@ if local.__module__ == 'gevent.local': ...@@ -600,7 +600,7 @@ if local.__module__ == 'gevent.local':
local.__new__ = classmethod(__new__) local.__new__ = classmethod(__new__)
else: # pragma: no cover else: # pragma: no cover
# Make sure we revisit in case of changes to the (accelerator) module names. # Make sure we revisit in case of changes to the (accelerator) module names.
if local.__module__ != 'gevent._gevent_clocal': if local.__module__ != 'gevent._gevent_clocal': # pylint:disable=else-if-used
raise AssertionError("Module names changed (local: %r; __name__: %r); revisit this code" % ( raise AssertionError("Module names changed (local: %r; __name__: %r); revisit this code" % (
local.__module__, __name__) ) local.__module__, __name__) )
......
...@@ -322,7 +322,7 @@ class RLock(object): ...@@ -322,7 +322,7 @@ class RLock(object):
""" """
me = getcurrent() me = getcurrent()
if self._owner is me: if self._owner is me:
self._count = self._count + 1 self._count += 1
return 1 return 1
rc = self._block.acquire(blocking, timeout) rc = self._block.acquire(blocking, timeout)
if rc: if rc:
...@@ -344,7 +344,7 @@ class RLock(object): ...@@ -344,7 +344,7 @@ class RLock(object):
raise RuntimeError("cannot release un-acquired lock. Owner: %r Current: %r" % ( raise RuntimeError("cannot release un-acquired lock. Owner: %r Current: %r" % (
self._owner, getcurrent() self._owner, getcurrent()
)) ))
self._count = count = self._count - 1 self._count = count = self._count - 1 # pylint:disable=consider-using-augmented-assign
if not count: if not count:
self._owner = None self._owner = None
self._block.release() self._block.release()
......
...@@ -44,7 +44,7 @@ to manage child processes. ...@@ -44,7 +44,7 @@ to manage child processes.
from __future__ import absolute_import from __future__ import absolute_import
import os import os
import sys
from gevent.hub import _get_hub_noargs as get_hub from gevent.hub import _get_hub_noargs as get_hub
from gevent.hub import reinit from gevent.hub import reinit
from gevent._config import config from gevent._config import config
......
...@@ -989,7 +989,7 @@ class WSGIHandler(object): ...@@ -989,7 +989,7 @@ class WSGIHandler(object):
finally: finally:
try: try:
self.wsgi_input._discard() self.wsgi_input._discard()
except (socket.error, IOError): except socket.error:
# Don't let exceptions during discarding # Don't let exceptions during discarding
# input override any exception that may have been # input override any exception that may have been
# raised by the application, such as our own _InvalidClientInput. # raised by the application, such as our own _InvalidClientInput.
......
...@@ -228,7 +228,7 @@ class Queue(object): ...@@ -228,7 +228,7 @@ class Queue(object):
""" """
return True return True
def __nonzero__(self): def __nonzero__(self): # pylint:disable=bad-dunder-name
# Py2. # Py2.
# For Cython; __bool__ becomes a special method that we can't # For Cython; __bool__ becomes a special method that we can't
# get by name. # get by name.
......
...@@ -149,7 +149,6 @@ def _is_addr(host, parse=_ipv4_inet_aton): ...@@ -149,7 +149,6 @@ def _is_addr(host, parse=_ipv4_inet_aton):
parse(host) parse(host)
except AddressSyntaxError: except AddressSyntaxError:
return False return False
else:
return True return True
# Return True if host is a valid IPv4 address # Return True if host is a valid IPv4 address
......
...@@ -89,7 +89,7 @@ class HostsFile(object): ...@@ -89,7 +89,7 @@ class HostsFile(object):
try: try:
load_time = os.stat(self.fname).st_mtime load_time = os.stat(self.fname).st_mtime
needs_load = load_time > self._last_load needs_load = load_time > self._last_load
except (IOError, OSError): except OSError:
from gevent import get_hub from gevent import get_hub
get_hub().handle_error(self, *sys.exc_info()) get_hub().handle_error(self, *sys.exc_info())
needs_load = False needs_load = False
......
...@@ -70,7 +70,6 @@ def get_fileno(obj): ...@@ -70,7 +70,6 @@ def get_fileno(obj):
if not isinstance(obj, integer_types): if not isinstance(obj, integer_types):
raise TypeError('argument must be an int, or have a fileno() method: %r' % (obj,)) raise TypeError('argument must be an int, or have a fileno() method: %r' % (obj,))
return obj return obj
else:
return fileno_f() return fileno_f()
......
...@@ -15,7 +15,6 @@ from _socket import SOCK_DGRAM ...@@ -15,7 +15,6 @@ from _socket import SOCK_DGRAM
from gevent.baseserver import BaseServer from gevent.baseserver import BaseServer
from gevent.socket import EWOULDBLOCK from gevent.socket import EWOULDBLOCK
from gevent.socket import socket as GeventSocket from gevent.socket import socket as GeventSocket
from gevent._compat import PYPY
__all__ = ['StreamServer', 'DatagramServer'] __all__ = ['StreamServer', 'DatagramServer']
......
...@@ -59,14 +59,10 @@ from gevent.hub import linkproxy ...@@ -59,14 +59,10 @@ from gevent.hub import linkproxy
from gevent.hub import sleep from gevent.hub import sleep
from gevent.hub import getcurrent from gevent.hub import getcurrent
from gevent._compat import integer_types, string_types, xrange from gevent._compat import integer_types, string_types, xrange
# from gevent._compat import PY3
# from gevent._compat import PY35
# from gevent._compat import PY36
# from gevent._compat import PY37
# from gevent._compat import PY38
from gevent._compat import PY311 from gevent._compat import PY311
from gevent._compat import PYPY from gevent._compat import PYPY
from gevent._compat import reraise
from gevent._compat import fsdecode from gevent._compat import fsdecode
from gevent._compat import fsencode from gevent._compat import fsencode
from gevent._compat import PathLike from gevent._compat import PathLike
...@@ -539,7 +535,7 @@ class _CommunicatingGreenlets(object): ...@@ -539,7 +535,7 @@ class _CommunicatingGreenlets(object):
if hasattr(fobj, 'flush'): if hasattr(fobj, 'flush'):
# 3.6 started expecting flush to be called. # 3.6 started expecting flush to be called.
fobj.flush() fobj.flush()
except (OSError, IOError, BrokenPipeError) as ex: except (OSError, BrokenPipeError) as ex:
# Test cases from the stdlib can raise BrokenPipeError # Test cases from the stdlib can raise BrokenPipeError
# without setting an errno value. This matters because # without setting an errno value. This matters because
# Python 2 doesn't have a BrokenPipeError. # Python 2 doesn't have a BrokenPipeError.
...@@ -824,7 +820,7 @@ class Popen(object): ...@@ -824,7 +820,7 @@ class Popen(object):
for f in filter(None, (self.stdin, self.stdout, self.stderr)): for f in filter(None, (self.stdin, self.stdout, self.stderr)):
try: try:
f.close() f.close()
except (OSError, IOError): except OSError:
pass # Ignore EBADF or other errors. pass # Ignore EBADF or other errors.
if not self._closed_child_pipe_fds: if not self._closed_child_pipe_fds:
...@@ -840,7 +836,7 @@ class Popen(object): ...@@ -840,7 +836,7 @@ class Popen(object):
for fd in to_close: for fd in to_close:
try: try:
os.close(fd) os.close(fd)
except (OSError, IOError): except OSError:
pass pass
raise raise
...@@ -1682,7 +1678,7 @@ class Popen(object): ...@@ -1682,7 +1678,7 @@ class Popen(object):
# same fd more than once, or standard fds. # same fd more than once, or standard fds.
if not True: if not True:
closed = set([None]) closed = set([None])
for fd in [p2cread, c2pwrite, errwrite]: for fd in (p2cread, c2pwrite, errwrite):
if fd not in closed and fd > 2: if fd not in closed and fd > 2:
os.close(fd) os.close(fd)
closed.add(fd) closed.add(fd)
......
...@@ -82,7 +82,7 @@ def walk_modules( ...@@ -82,7 +82,7 @@ def walk_modules(
if modpath is None: if modpath is None:
modpath = 'gevent.' modpath = 'gevent.'
else: else:
if modpath is None: if modpath is None: # pylint:disable=else-if-used
modpath = '' modpath = ''
for fn in sorted(os.listdir(basedir)): for fn in sorted(os.listdir(basedir)):
......
...@@ -34,7 +34,7 @@ from . import travis ...@@ -34,7 +34,7 @@ from . import travis
# See https://bitbucket.org/pypy/pypy/issues/2769/systemerror-unexpected-internal-exception # See https://bitbucket.org/pypy/pypy/issues/2769/systemerror-unexpected-internal-exception
try: try:
__import__('_testcapi') __import__('_testcapi')
except (ImportError, OSError, IOError): except (ImportError, OSError):
# This can raise a wide variety of errors # This can raise a wide variety of errors
pass pass
...@@ -521,7 +521,7 @@ class Discovery(object): ...@@ -521,7 +521,7 @@ class Discovery(object):
not os.path.exists(abs_filename) not os.path.exists(abs_filename)
and not filename.endswith('.py') and not filename.endswith('.py')
and os.path.exists(abs_filename + '.py') ): and os.path.exists(abs_filename + '.py') ):
abs_filename = abs_filename + '.py' abs_filename += '.py'
with open(abs_filename, 'rb') as f: with open(abs_filename, 'rb') as f:
# Some of the test files (e.g., test__socket_dns) are # Some of the test files (e.g., test__socket_dns) are
......
...@@ -358,7 +358,7 @@ def _find_test_status(took, out): ...@@ -358,7 +358,7 @@ def _find_test_status(took, out):
if m: if m:
skipped = _colorize('skipped', out[m.start():m.end()]) skipped = _colorize('skipped', out[m.start():m.end()])
skipped_count = int(out[m.start(1):m.end(1)]) skipped_count = int(out[m.start(1):m.end(1)])
status = status % (took, skipped) status = status % (took, skipped) # pylint:disable=consider-using-augmented-assign
if took > 10: if took > 10:
status = _colorize('slow-test', status) status = _colorize('slow-test', status)
return status, run_count, skipped_count return status, run_count, skipped_count
......
...@@ -17,9 +17,6 @@ class Condition(object): ...@@ -17,9 +17,6 @@ class Condition(object):
def __or__(self, other): def __or__(self, other):
return OrCondition(self, other) return OrCondition(self, other)
def __nonzero__(self):
return self.__bool__()
def __bool__(self): def __bool__(self):
raise NotImplementedError raise NotImplementedError
...@@ -184,7 +181,7 @@ class DefinitionsMeta(type): ...@@ -184,7 +181,7 @@ class DefinitionsMeta(type):
# a metaclass on Python 3 that makes sure we only set attributes once. pylint doesn't # a metaclass on Python 3 that makes sure we only set attributes once. pylint doesn't
# warn about that. # warn about that.
@classmethod @classmethod
def __prepare__(cls, name, bases): # pylint:disable=unused-argument def __prepare__(mcs, name, bases): # pylint:disable=unused-argument,bad-dunder-name
return SetOnceMapping() return SetOnceMapping()
......
...@@ -10,12 +10,8 @@ else: ...@@ -10,12 +10,8 @@ else:
print(os.path.abspath(__file__)) print(os.path.abspath(__file__))
if sys.version_info[:2] == (2, 7):
# Prior to gevent 1.3, 'python -m gevent.monkey' guaranteed this to be if sys.argv[1] == 'patched':
# None for all python versions.
print(__package__ is None)
else:
if sys.argv[1] == 'patched':
# __package__ is handled differently, for some reason, and # __package__ is handled differently, for some reason, and
# runpy doesn't let us override it. When we call it, it # runpy doesn't let us override it. When we call it, it
# becomes ''. This appears to be against the documentation for # becomes ''. This appears to be against the documentation for
...@@ -24,7 +20,7 @@ else: ...@@ -24,7 +20,7 @@ else:
# precompiled byte code), then __file__ will be set to the # precompiled byte code), then __file__ will be set to the
# supplied path, and __spec__, __cached__, __loader__ and # supplied path, and __spec__, __cached__, __loader__ and
# __package__ will all be set to None." # __package__ will all be set to None."
print(__package__ == '') print(__package__ == '') # pylint:disable=compare-to-empty-string
else: else:
# but the interpreter sets it to None # but the interpreter sets it to None
print(__package__ is None) print(__package__ is None)
...@@ -159,7 +159,7 @@ class Test(greentest.TestCase): ...@@ -159,7 +159,7 @@ class Test(greentest.TestCase):
start = time.time() start = time.time()
with Timeout(XDELAY, False): with Timeout(XDELAY, False):
sleep(XDELAY * 2) sleep(XDELAY * 2)
delta = (time.time() - start) delta = time.time() - start
self.assertTimeWithinRange(delta, 0, XDELAY * 2) self.assertTimeWithinRange(delta, 0, XDELAY * 2)
# passing None as seconds disables the timer # passing None as seconds disables the timer
......
...@@ -73,7 +73,7 @@ class Test(greentest.TestCase): ...@@ -73,7 +73,7 @@ class Test(greentest.TestCase):
except: except:
conn.close() conn.close()
raise raise
else:
conn.banner = banner conn.banner = banner
return conn return conn
......
...@@ -37,7 +37,7 @@ def _find_files_to_ignore(): ...@@ -37,7 +37,7 @@ def _find_files_to_ignore():
return result return result
default_time_range = (2, 10) default_time_range = (2, 10)
time_ranges = { time_ranges = { # what is this even supposed to mean? pylint:disable=consider-using-namedtuple-or-dataclass
'concurrent_download.py': (0, 30), 'concurrent_download.py': (0, 30),
'processes.py': (0, default_time_range[-1]) 'processes.py': (0, default_time_range[-1])
} }
......
...@@ -34,7 +34,7 @@ def Writer(fobj, line): ...@@ -34,7 +34,7 @@ def Writer(fobj, line):
def close_fd_quietly(fd): def close_fd_quietly(fd):
try: try:
os.close(fd) os.close(fd)
except (IOError, OSError): except OSError:
pass pass
def skipUnlessWorksWithRegularFiles(func): def skipUnlessWorksWithRegularFiles(func):
...@@ -275,7 +275,7 @@ class TestFileObjectBlock(CleanupMixin, ...@@ -275,7 +275,7 @@ class TestFileObjectBlock(CleanupMixin,
f.close() f.close()
try: try:
nf.close() nf.close()
except (OSError, IOError): except OSError:
# OSError: Py3, IOError: Py2 # OSError: Py3, IOError: Py2
pass pass
self.assertEqual(f.name, fileno) self.assertEqual(f.name, fileno)
......
...@@ -68,7 +68,7 @@ class TestDestroyInChildWithActiveSpawn(unittest.TestCase): ...@@ -68,7 +68,7 @@ class TestDestroyInChildWithActiveSpawn(unittest.TestCase):
hub.destroy(destroy_loop=True) hub.destroy(destroy_loop=True)
self.assertFalse(run) self.assertFalse(run)
os._exit(0) os._exit(0)
return return # pylint:disable=unreachable
# The parent. # The parent.
# Briefly prevent us from spinning our event loop. # Briefly prevent us from spinning our event loop.
......
...@@ -47,7 +47,7 @@ class Test(greentest.TestCase): ...@@ -47,7 +47,7 @@ class Test(greentest.TestCase):
def assert_raises_EBADF(self, func): def assert_raises_EBADF(self, func):
try: try:
result = func() result = func()
except (socket.error, OSError) as ex: except OSError as ex:
# Windows/Py3 raises "OSError: [WinError 10038]" # Windows/Py3 raises "OSError: [WinError 10038]"
if ex.args[0] == errno.EBADF: if ex.args[0] == errno.EBADF:
return return
......
...@@ -817,6 +817,7 @@ class TestUseWrite(TestCase): ...@@ -817,6 +817,7 @@ class TestUseWrite(TestCase):
write(self.body) write(self.body)
write(self.body) write(self.body)
else: else:
# pylint:disable-next=broad-exception-raised
raise Exception('Invalid url') raise Exception('Invalid url')
return [self.end] return [self.end]
...@@ -1145,7 +1146,6 @@ class TestContentLength304(TestCase): ...@@ -1145,7 +1146,6 @@ class TestContentLength304(TestCase):
except AssertionError as ex: except AssertionError as ex:
start_response('200 Raised', []) start_response('200 Raised', [])
return ex.args return ex.args
else:
raise AssertionError('start_response did not fail but it should') raise AssertionError('start_response did not fail but it should')
def test_err(self): def test_err(self):
...@@ -1699,7 +1699,7 @@ class TestInputRaw(greentest.BaseTestCase): ...@@ -1699,7 +1699,7 @@ class TestInputRaw(greentest.BaseTestCase):
data = b'asdf\nghij\n' data = b'asdf\nghij\n'
long_data = b'a' * (pywsgi.MAX_REQUEST_LINE + 10) long_data = b'a' * (pywsgi.MAX_REQUEST_LINE + 10)
long_data += b'\n' long_data += b'\n'
data = data + long_data data += long_data
partial_data = b'qjk\n' # Note terminating \n partial_data = b'qjk\n' # Note terminating \n
n = 25 * 1000000000 n = 25 * 1000000000
if hasattr(n, 'bit_length'): if hasattr(n, 'bit_length'):
......
...@@ -198,7 +198,7 @@ class TestTCP(greentest.TestCase): ...@@ -198,7 +198,7 @@ class TestTCP(greentest.TestCase):
# from generating ``ConnectionResetError`` on AppVeyor. # from generating ``ConnectionResetError`` on AppVeyor.
try: try:
client = client.unwrap() client = client.unwrap()
except (ValueError, IOError, OSError): except (ValueError, OSError):
# PyPy raises _cffi_ssl._stdssl.error.SSLSyscallError, # PyPy raises _cffi_ssl._stdssl.error.SSLSyscallError,
# which is an IOError in 2.7 and OSError in 3.7 # which is an IOError in 2.7 and OSError in 3.7
pass pass
...@@ -214,7 +214,7 @@ class TestTCP(greentest.TestCase): ...@@ -214,7 +214,7 @@ class TestTCP(greentest.TestCase):
# lets do a shutdown everywhere, but only after removing any # lets do a shutdown everywhere, but only after removing any
# SSL wrapping. # SSL wrapping.
client.shutdown(socket.SHUT_RDWR) client.shutdown(socket.SHUT_RDWR)
except (OSError, socket.error): except OSError:
pass pass
log("Client will close") log("Client will close")
......
...@@ -14,7 +14,7 @@ class TestClosedSocket(greentest.TestCase): ...@@ -14,7 +14,7 @@ class TestClosedSocket(greentest.TestCase):
try: try:
sock.send(b'a', timeout=1) sock.send(b'a', timeout=1)
self.fail("Should raise socket error") self.fail("Should raise socket error")
except (socket.error, OSError) as ex: except OSError as ex:
if ex.args[0] != errno.EBADF: if ex.args[0] != errno.EBADF:
if sys.platform.startswith('win'): if sys.platform.startswith('win'):
# Windows/Py3 raises "OSError: [WinError 10038] " # Windows/Py3 raises "OSError: [WinError 10038] "
......
...@@ -66,10 +66,8 @@ class TestLockThread(greentest.TestCase): ...@@ -66,10 +66,8 @@ class TestLockThread(greentest.TestCase):
def background(): def background():
spawned.append(True) spawned.append(True)
while 1: while not lock.acquire(False):
# blocking= in Py3, wait (no default, no name) in Py2 pass
if lock.acquire(False):
break
thread = threading.Thread(target=background) thread = threading.Thread(target=background)
# If lock.acquire(False) doesn't yield when it fails, # If lock.acquire(False) doesn't yield when it fails,
......
...@@ -510,7 +510,7 @@ class SomeClass(object): ...@@ -510,7 +510,7 @@ class SomeClass(object):
def func(self, arg1, kwarg1=None): def func(self, arg1, kwarg1=None):
result = Object() result = Object()
self.refs.extend([weakref.ref(x) for x in [arg1, kwarg1, result]]) self.refs.extend([weakref.ref(x) for x in (arg1, kwarg1, result)])
return result return result
......
...@@ -40,7 +40,7 @@ class TestFormat(greentest.TestCase): ...@@ -40,7 +40,7 @@ class TestFormat(greentest.TestCase):
def test_with_Greenlet(self): def test_with_Greenlet(self):
rl = local.local() rl = local.local()
rl.foo = 1 rl.some_attr = 1
def root(): def root():
l = MyLocal(42) l = MyLocal(42)
assert l assert l
......
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