update pylint version, and fix linter issues

This commit is contained in:
unknown 2023-05-17 18:45:59 +03:00
parent 6998d1247c
commit 48d670f087
19 changed files with 49 additions and 42 deletions

View File

@ -12,7 +12,6 @@ ignore=
disable= disable=
attribute-defined-outside-init, attribute-defined-outside-init,
bad-continuation,
bad-mcs-classmethod-argument, bad-mcs-classmethod-argument,
bare-except, bare-except,
broad-except, broad-except,
@ -25,12 +24,10 @@ disable=
import-self, import-self,
inconsistent-return-statements, inconsistent-return-statements,
invalid-name, invalid-name,
misplaced-comparison-constant,
missing-docstring, missing-docstring,
no-else-return, no-else-return,
no-member, no-member,
no-self-argument, no-self-argument,
no-self-use,
no-staticmethod-decorator, no-staticmethod-decorator,
not-callable, not-callable,
protected-access, protected-access,
@ -53,3 +50,6 @@ disable=
useless-import-alias, useless-import-alias,
comparison-with-callable, comparison-with-callable,
try-except-raise, try-except-raise,
consider-using-with,
consider-using-f-string,
unspecified-encoding

View File

@ -1510,7 +1510,8 @@ class LogConfigDict(Setting):
Format: https://docs.python.org/3/library/logging.config.html#logging.config.dictConfig Format: https://docs.python.org/3/library/logging.config.html#logging.config.dictConfig
For more context you can look at the default configuration dictionary for logging, which can be found at ``gunicorn.glogging.CONFIG_DEFAULTS``. For more context you can look at the default configuration dictionary for logging,
which can be found at ``gunicorn.glogging.CONFIG_DEFAULTS``.
.. versionadded:: 19.8 .. versionadded:: 19.8
""" """
@ -1993,6 +1994,7 @@ class OnExit(Setting):
The callable needs to accept a single instance variable for the Arbiter. The callable needs to accept a single instance variable for the Arbiter.
""" """
class NewSSLContext(Setting): class NewSSLContext(Setting):
name = "ssl_context" name = "ssl_context"
section = "Server Hooks" section = "Server Hooks"
@ -2027,6 +2029,7 @@ class NewSSLContext(Setting):
.. versionadded:: 20.2 .. versionadded:: 20.2
""" """
class ProxyProtocol(Setting): class ProxyProtocol(Setting):
name = "proxy_protocol" name = "proxy_protocol"
section = "Server Mechanics" section = "Server Mechanics"

View File

@ -45,12 +45,11 @@ SYSLOG_FACILITIES = {
"local7": 23 "local7": 23
} }
CONFIG_DEFAULTS = dict( CONFIG_DEFAULTS = {
version=1, "version": 1,
disable_existing_loggers=False, "disable_existing_loggers": False,
"root": {"level": "INFO", "handlers": ["console"]},
root={"level": "INFO", "handlers": ["console"]}, "loggers": {
loggers={
"gunicorn.error": { "gunicorn.error": {
"level": "INFO", "level": "INFO",
"handlers": ["error_console"], "handlers": ["error_console"],
@ -65,7 +64,7 @@ CONFIG_DEFAULTS = dict(
"qualname": "gunicorn.access" "qualname": "gunicorn.access"
} }
}, },
handlers={ "handlers": {
"console": { "console": {
"class": "logging.StreamHandler", "class": "logging.StreamHandler",
"formatter": "generic", "formatter": "generic",
@ -77,14 +76,14 @@ CONFIG_DEFAULTS = dict(
"stream": "ext://sys.stderr" "stream": "ext://sys.stderr"
}, },
}, },
formatters={ "formatters": {
"generic": { "generic": {
"format": "%(asctime)s [%(process)d] [%(levelname)s] %(message)s", "format": "%(asctime)s [%(process)d] [%(levelname)s] %(message)s",
"datefmt": "[%Y-%m-%d %H:%M:%S %z]", "datefmt": "[%Y-%m-%d %H:%M:%S %z]",
"class": "logging.Formatter" "class": "logging.Formatter"
} }
} }
) }
def loggers(): def loggers():
@ -418,7 +417,7 @@ class Logger(object):
if output == "-": if output == "-":
h = logging.StreamHandler(stream) h = logging.StreamHandler(stream)
else: else:
util.check_is_writeable(output) util.check_is_writable(output)
h = logging.FileHandler(output) h = logging.FileHandler(output)
# make sure the user can reopen the file # make sure the user can reopen the file
try: try:

View File

@ -12,7 +12,7 @@ import sys
from gunicorn.http.message import HEADER_RE from gunicorn.http.message import HEADER_RE
from gunicorn.http.errors import InvalidHeader, InvalidHeaderName from gunicorn.http.errors import InvalidHeader, InvalidHeaderName
from gunicorn import SERVER_SOFTWARE, SERVER from gunicorn import SERVER_SOFTWARE, SERVER
import gunicorn.util as util from gunicorn import util
# Send files in at most 1GB blocks as some operating systems can have problems # Send files in at most 1GB blocks as some operating systems can have problems
# with sending files in blocks over 2GB. # with sending files in blocks over 2GB.

View File

@ -204,6 +204,7 @@ def create_sockets(conf, log, fds=None):
return listeners return listeners
def close_sockets(listeners, unlink=True): def close_sockets(listeners, unlink=True):
for sock in listeners: for sock in listeners:
sock_name = sock.getsockname() sock_name = sock.getsockname()
@ -211,6 +212,7 @@ def close_sockets(listeners, unlink=True):
if unlink and _sock_type(sock_name) is UnixSocket: if unlink and _sock_type(sock_name) is UnixSocket:
os.unlink(sock_name) os.unlink(sock_name)
def ssl_context(conf): def ssl_context(conf):
def default_ssl_context_factory(): def default_ssl_context_factory():
context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH, cafile=conf.ca_certs) context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH, cafile=conf.ca_certs)
@ -222,7 +224,9 @@ def ssl_context(conf):
return conf.ssl_context(conf, default_ssl_context_factory) return conf.ssl_context(conf, default_ssl_context_factory)
def ssl_wrap_socket(sock, conf): def ssl_wrap_socket(sock, conf):
return ssl_context(conf).wrap_socket(sock, server_side=True, return ssl_context(conf).wrap_socket(sock,
suppress_ragged_eofs=conf.suppress_ragged_eofs, server_side=True,
do_handshake_on_connect=conf.do_handshake_on_connect) suppress_ragged_eofs=conf.suppress_ragged_eofs,
do_handshake_on_connect=conf.do_handshake_on_connect)

View File

@ -562,12 +562,12 @@ def seed():
random.seed('%s.%s' % (time.time(), os.getpid())) random.seed('%s.%s' % (time.time(), os.getpid()))
def check_is_writeable(path): def check_is_writable(path):
try: try:
f = open(path, 'a') with open(path, 'a') as f:
f.close()
except IOError as e: except IOError as e:
raise RuntimeError("Error: '%s' isn't writable [%r]" % (path, e)) raise RuntimeError("Error: '%s' isn't writable [%r]" % (path, e))
f.close()
def to_bytestring(value, encoding="utf8"): def to_bytestring(value, encoding="utf8"):

View File

@ -9,10 +9,10 @@ import socket
import ssl import ssl
import sys import sys
import gunicorn.http as http from gunicorn import http
import gunicorn.http.wsgi as wsgi from gunicorn.http import wsgi
import gunicorn.util as util from gunicorn import util
import gunicorn.workers.base as base from gunicorn.workers import base
ALREADY_HANDLED = object() ALREADY_HANDLED = object()

View File

@ -173,6 +173,7 @@ class EventletWorker(AsyncWorker):
eventlet.sleep(1.0) eventlet.sleep(1.0)
self.notify() self.notify()
t = None
try: try:
with eventlet.Timeout(self.cfg.graceful_timeout) as t: with eventlet.Timeout(self.cfg.graceful_timeout) as t:
for a in acceptors: for a in acceptors:

View File

@ -59,7 +59,7 @@ class GeventWorker(AsyncWorker):
ssl_args = {} ssl_args = {}
if self.cfg.is_ssl: if self.cfg.is_ssl:
ssl_args = dict(ssl_context=ssl_context(self.cfg)) ssl_args = {"ssl_context": ssl_context(self.cfg)}
for s in self.sockets: for s in self.sockets:
s.setblocking(1) s.setblocking(1)

View File

@ -11,7 +11,7 @@
# closed. # closed.
# pylint: disable=no-else-break # pylint: disable=no-else-break
import concurrent.futures as futures from concurrent import futures
import errno import errno
import os import os
import selectors import selectors

View File

@ -3,7 +3,6 @@
# This file is part of gunicorn released under the MIT license. # This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information. # See the NOTICE for more information.
import copy
import os import os
import sys import sys
@ -112,7 +111,7 @@ class TornadoWorker(Worker):
isinstance(app, tornado.wsgi.WSGIApplication): isinstance(app, tornado.wsgi.WSGIApplication):
app = WSGIContainer(app) app = WSGIContainer(app)
elif not isinstance(app, WSGIContainer) and \ elif not isinstance(app, WSGIContainer) and \
not isinstance(app, tornado.web.Application): not isinstance(app, tornado.web.Application):
app = WSGIContainer(app) app = WSGIContainer(app)
# Monkey-patching HTTPConnection.finish to count the # Monkey-patching HTTPConnection.finish to count the

View File

@ -12,11 +12,11 @@ import socket
import ssl import ssl
import sys import sys
import gunicorn.http as http from gunicorn import http
import gunicorn.http.wsgi as wsgi from gunicorn.http import wsgi
import gunicorn.sock as sock from gunicorn import sock
import gunicorn.util as util from gunicorn import util
import gunicorn.workers.base as base from gunicorn.workers import base
class StopWaiting(Exception): class StopWaiting(Exception):

View File

@ -4,7 +4,7 @@
# See the NOTICE for more information. # See the NOTICE for more information.
import os import os
import unittest.mock as mock from unittest import mock
import gunicorn.app.base import gunicorn.app.base
import gunicorn.arbiter import gunicorn.arbiter

View File

@ -3,7 +3,7 @@
import io import io
import t import t
import pytest import pytest
import unittest.mock as mock from unittest import mock
from gunicorn import util from gunicorn import util
from gunicorn.http.body import Body, LengthReader, EOFReader from gunicorn.http.body import Body, LengthReader, EOFReader

View File

@ -4,7 +4,7 @@
# See the NOTICE for more information. # See the NOTICE for more information.
import errno import errno
import unittest.mock as mock from unittest import mock
import gunicorn.pidfile import gunicorn.pidfile

View File

@ -3,7 +3,7 @@
# This file is part of gunicorn released under the MIT license. # This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information. # See the NOTICE for more information.
import unittest.mock as mock from unittest import mock
from gunicorn import sock from gunicorn import sock

View File

@ -8,7 +8,7 @@
import pytest import pytest
from gunicorn.config import ( from gunicorn.config import (
KeyFile, CertFile, SSLVersion, CACerts, SuppressRaggedEOFs, KeyFile, CertFile, CACerts, SuppressRaggedEOFs,
DoHandshakeOnConnect, Setting, Ciphers, DoHandshakeOnConnect, Setting, Ciphers,
) )

View File

@ -5,7 +5,7 @@
from contextlib import contextmanager from contextlib import contextmanager
import os import os
import unittest.mock as mock from unittest import mock
import pytest import pytest

View File

@ -12,6 +12,7 @@ deps =
[testenv:lint] [testenv:lint]
commands = commands =
pylint -j0 \ pylint -j0 \
--max-line-length=120 \
gunicorn \ gunicorn \
tests/test_arbiter.py \ tests/test_arbiter.py \
tests/test_config.py \ tests/test_config.py \
@ -26,7 +27,7 @@ commands =
tests/test_util.py \ tests/test_util.py \
tests/test_valid_requests.py tests/test_valid_requests.py
deps = deps =
pylint<2.7 pylint=2.17.4
[testenv:docs-lint] [testenv:docs-lint]
allowlist_externals = allowlist_externals =