From 76eaa0805b0d2d19b8e6f0690461ddaceb80e16f Mon Sep 17 00:00:00 2001 From: Berker Peksag Date: Wed, 10 Jan 2018 02:11:24 +0300 Subject: [PATCH] Fix various warnings and errors reported by pylint --- gunicorn/app/base.py | 3 +++ gunicorn/app/pasterapp.py | 9 ++++++--- gunicorn/arbiter.py | 2 +- gunicorn/debug.py | 5 ++--- gunicorn/errors.py | 8 +++++++- gunicorn/http/errors.py | 6 ++++++ gunicorn/http/message.py | 2 +- gunicorn/http/wsgi.py | 3 +++ gunicorn/instrument/statsd.py | 2 +- gunicorn/sock.py | 2 +- gunicorn/util.py | 2 +- gunicorn/workers/gaiohttp.py | 2 +- tests/config/test_cfg.py | 2 +- tests/support.py | 2 +- tests/test_http.py | 2 +- tests/test_util.py | 2 +- 16 files changed, 37 insertions(+), 17 deletions(-) diff --git a/gunicorn/app/base.py b/gunicorn/app/base.py index 2caa9e09..e468c956 100644 --- a/gunicorn/app/base.py +++ b/gunicorn/app/base.py @@ -78,6 +78,9 @@ class BaseApplication(object): class Application(BaseApplication): + # 'init' and 'load' methods are implemented by WSGIApplication. + # pylint: disable=abstract-method + def chdir(self): # chdir to the configured path before loading, # default is the current dir diff --git a/gunicorn/app/pasterapp.py b/gunicorn/app/pasterapp.py index 33f62b0b..dbcd339d 100644 --- a/gunicorn/app/pasterapp.py +++ b/gunicorn/app/pasterapp.py @@ -4,6 +4,8 @@ # See the NOTICE for more information. from __future__ import print_function +# pylint: skip-file + import os import pkg_resources import sys @@ -120,7 +122,8 @@ class PasterApplication(PasterBaseApplication): class PasterServerApplication(PasterBaseApplication): - def __init__(self, app, gcfg=None, host="127.0.0.1", port=None, *args, **kwargs): + def __init__(self, app, gcfg=None, host="127.0.0.1", port=None, **kwargs): + # pylint: disable=super-init-not-called self.cfg = Config() self.gcfg = gcfg # need to hold this for app_config self.app = app @@ -182,7 +185,7 @@ def run(): PasterApplication("%(prog)s [OPTIONS] pasteconfig.ini").run() -def paste_server(app, gcfg=None, host="127.0.0.1", port=None, *args, **kwargs): +def paste_server(app, gcfg=None, host="127.0.0.1", port=None, **kwargs): """\ A paster server. @@ -203,4 +206,4 @@ def paste_server(app, gcfg=None, host="127.0.0.1", port=None, *args, **kwargs): """) from gunicorn.app.pasterapp import PasterServerApplication - PasterServerApplication(app, gcfg=gcfg, host=host, port=port, *args, **kwargs).run() + PasterServerApplication(app, gcfg=gcfg, host=host, port=port, **kwargs).run() diff --git a/gunicorn/arbiter.py b/gunicorn/arbiter.py index 7ddd4ab8..083ee6a0 100644 --- a/gunicorn/arbiter.py +++ b/gunicorn/arbiter.py @@ -573,7 +573,7 @@ class Arbiter(object): # Do not inherit the temporary files of other workers for sibling in self.WORKERS.values(): sibling.tmp.close() - + # Process Child worker.pid = os.getpid() try: diff --git a/gunicorn/debug.py b/gunicorn/debug.py index 1b7834fa..996fe1b4 100644 --- a/gunicorn/debug.py +++ b/gunicorn/debug.py @@ -13,12 +13,11 @@ import inspect __all__ = ['spew', 'unspew'] -_token_spliter = re.compile('\W+') +_token_spliter = re.compile(r'\W+') class Spew(object): - """ - """ + def __init__(self, trace_names=None, show_values=True): self.trace_names = trace_names self.show_values = show_values diff --git a/gunicorn/errors.py b/gunicorn/errors.py index 487d4380..727d336a 100644 --- a/gunicorn/errors.py +++ b/gunicorn/errors.py @@ -3,8 +3,14 @@ # This file is part of gunicorn released under the MIT license. # See the NOTICE for more information. +# We don't need to call super() in __init__ methods of our +# BaseException and Exception classes because we also define +# our own __str__ methods so there is no need to pass 'message' +# to the base class to get a meaningful output from 'str(exc)'. +# pylint: disable=super-init-not-called -# we inherit from BaseException here to make sure to not be caucght + +# we inherit from BaseException here to make sure to not be caught # at application level class HaltServer(BaseException): def __init__(self, reason, exit_status=1): diff --git a/gunicorn/http/errors.py b/gunicorn/http/errors.py index d284a059..7839ef05 100644 --- a/gunicorn/http/errors.py +++ b/gunicorn/http/errors.py @@ -3,6 +3,12 @@ # This file is part of gunicorn released under the MIT license. # See the NOTICE for more information. +# We don't need to call super() in __init__ methods of our +# BaseException and Exception classes because we also define +# our own __str__ methods so there is no need to pass 'message' +# to the base class to get a meaningful output from 'str(exc)'. +# pylint: disable=super-init-not-called + class ParseException(Exception): pass diff --git a/gunicorn/http/message.py b/gunicorn/http/message.py index 96e3adc5..691f33eb 100644 --- a/gunicorn/http/message.py +++ b/gunicorn/http/message.py @@ -22,7 +22,7 @@ MAX_REQUEST_LINE = 8190 MAX_HEADERS = 32768 DEFAULT_MAX_HEADERFIELD_SIZE = 8190 -HEADER_RE = re.compile("[\x00-\x1F\x7F()<>@,;:\[\]={} \t\\\\\"]") +HEADER_RE = re.compile(r"[\x00-\x1F\x7F()<>@,;:\[\]={} \t\\\"]") METH_RE = re.compile(r"[A-Z0-9$-_.]{3,20}") VERSION_RE = re.compile(r"HTTP/(\d+)\.(\d+)") diff --git a/gunicorn/http/wsgi.py b/gunicorn/http/wsgi.py index 13b96eea..6b017357 100644 --- a/gunicorn/http/wsgi.py +++ b/gunicorn/http/wsgi.py @@ -52,6 +52,9 @@ class FileWrapper(object): class WSGIErrorsWrapper(io.RawIOBase): def __init__(self, cfg): + # There is no public __init__ method for RawIOBase so + # we don't need to call super() in the __init__ method. + # pylint: disable=super-init-not-called errorlog = logging.getLogger("gunicorn.error") handlers = errorlog.handlers self.streams = [] diff --git a/gunicorn/instrument/statsd.py b/gunicorn/instrument/statsd.py index e0c6882e..4bbcb20a 100644 --- a/gunicorn/instrument/statsd.py +++ b/gunicorn/instrument/statsd.py @@ -27,7 +27,7 @@ class Statsd(Logger): """host, port: statsD server """ Logger.__init__(self, cfg) - self.prefix = sub(r"^(.+[^.]+)\.*$", "\g<1>.", cfg.statsd_prefix) + self.prefix = sub(r"^(.+[^.]+)\.*$", "\\g<1>.", cfg.statsd_prefix) try: host, port = cfg.statsd_host self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) diff --git a/gunicorn/sock.py b/gunicorn/sock.py index bbb32aaa..8870936a 100644 --- a/gunicorn/sock.py +++ b/gunicorn/sock.py @@ -39,7 +39,7 @@ class BaseSocket(object): def set_options(self, sock, bound=False): sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) - if (self.conf.reuse_port + if (self.conf.reuse_port and hasattr(socket, 'SO_REUSEPORT')): # pragma: no cover try: sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1) diff --git a/gunicorn/util.py b/gunicorn/util.py index a7d5514a..d6d99fc1 100644 --- a/gunicorn/util.py +++ b/gunicorn/util.py @@ -199,7 +199,7 @@ if sys.platform.startswith("win"): # Other Windows APIs can fail or give incorrect results when # dealing with files that are pending deletion. L = os.listdir(dirname) - if not (L if waitall else name in L): + if not L if waitall else name in L: return # Increase the timeout and try again time.sleep(timeout) diff --git a/gunicorn/workers/gaiohttp.py b/gunicorn/workers/gaiohttp.py index 7d0227a8..bef6b495 100644 --- a/gunicorn/workers/gaiohttp.py +++ b/gunicorn/workers/gaiohttp.py @@ -9,7 +9,7 @@ from gunicorn import util if sys.version_info >= (3, 4): try: - import aiohttp # NOQA + import aiohttp # pylint: disable=unused-import except ImportError: raise RuntimeError("You need aiohttp installed to use this worker.") else: diff --git a/tests/config/test_cfg.py b/tests/config/test_cfg.py index 70b8074b..53f0e6fa 100644 --- a/tests/config/test_cfg.py +++ b/tests/config/test_cfg.py @@ -1,4 +1,4 @@ bind = "unix:/tmp/bar/baz" workers = 3 proc_name = "fooey" -default_proc_name = "blurgh" \ No newline at end of file +default_proc_name = "blurgh" diff --git a/tests/support.py b/tests/support.py index 1f082211..11782a30 100644 --- a/tests/support.py +++ b/tests/support.py @@ -50,7 +50,7 @@ def requires_mac_ver(*min_version): return decorator try: - from types import SimpleNamespace # noqa + from types import SimpleNamespace # pylint: disable=unused-import except ImportError: class SimpleNamespace(object): def __init__(self, **kwargs): diff --git a/tests/test_http.py b/tests/test_http.py index ddea58ca..628039ce 100644 --- a/tests/test_http.py +++ b/tests/test_http.py @@ -92,7 +92,7 @@ def test_http_header_encoding(): header_str = "%s\r\n" % "".join(tosend) with pytest.raises(UnicodeEncodeError): - mocked_socket.sendall(util.to_bytestring(header_str,"ascii")) + mocked_socket.sendall(util.to_bytestring(header_str, "ascii")) def test_http_invalid_response_header(): diff --git a/tests/test_util.py b/tests/test_util.py index 5d3c8db5..11d74898 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -7,7 +7,7 @@ import pytest from gunicorn import util from gunicorn.errors import AppImportError -from gunicorn.six.moves.urllib.parse import SplitResult +from gunicorn.six.moves.urllib.parse import SplitResult # pylint: disable=no-name-in-module @pytest.mark.parametrize('test_input, expected', [