Fix various warnings and errors reported by pylint

This commit is contained in:
Berker Peksag 2018-01-10 02:11:24 +03:00
parent 249783567f
commit 76eaa0805b
16 changed files with 37 additions and 17 deletions

View File

@ -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

View File

@ -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()

View File

@ -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:

View File

@ -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

View File

@ -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):

View File

@ -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

View File

@ -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+)")

View File

@ -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 = []

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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:

View File

@ -1,4 +1,4 @@
bind = "unix:/tmp/bar/baz"
workers = 3
proc_name = "fooey"
default_proc_name = "blurgh"
default_proc_name = "blurgh"

View File

@ -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):

View File

@ -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():

View File

@ -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', [