chore: refactor code quality issues (#2044)

This commit is contained in:
Aksh Gupta 2021-03-05 13:56:03 +05:30 committed by GitHub
parent 00a1ee0cb6
commit 0d2d62eae5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 35 additions and 21 deletions

12
.deepsource.toml Normal file
View File

@ -0,0 +1,12 @@
version = 1
test_patterns = ["tests/**"]
exclude_patterns = ["docker/**"]
[[analyzers]]
name = "python"
enabled = true
[analyzers.meta]
runtime_version = "3.x.x"

View File

@ -19,7 +19,7 @@ class ListenerEvent(str, Enum):
class ListenerMixin: class ListenerMixin:
def __init__(self, *args, **kwargs) -> None: def __init__(self, *args, **kwargs) -> None:
self._future_listeners: List[FutureListener] = list() self._future_listeners: List[FutureListener] = []
def _apply_listener(self, listener: FutureListener): def _apply_listener(self, listener: FutureListener):
raise NotImplementedError # noqa raise NotImplementedError # noqa

View File

@ -6,7 +6,7 @@ from sanic.models.futures import FutureMiddleware
class MiddlewareMixin: class MiddlewareMixin:
def __init__(self, *args, **kwargs) -> None: def __init__(self, *args, **kwargs) -> None:
self._future_middleware: List[FutureMiddleware] = list() self._future_middleware: List[FutureMiddleware] = []
def _apply_middleware(self, middleware: FutureMiddleware): def _apply_middleware(self, middleware: FutureMiddleware):
raise NotImplementedError # noqa raise NotImplementedError # noqa

View File

@ -177,7 +177,7 @@ class WebSocketConnection:
{ {
"type": "websocket.accept", "type": "websocket.accept",
"subprotocol": ",".join( "subprotocol": ",".join(
[subprotocol for subprotocol in self.subprotocols] list(self.subprotocols)
), ),
} }
) )

View File

@ -5,7 +5,7 @@ import signal
import sys import sys
import traceback import traceback
from gunicorn.workers import base as base # type: ignore from gunicorn.workers import base # type: ignore
from sanic.log import logger from sanic.log import logger
from sanic.server import HttpProtocol, Signal, serve, trigger_events from sanic.server import HttpProtocol, Signal, serve, trigger_events

View File

@ -1,6 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
from os import path from os import path
import sys
if __name__ == "__main__": if __name__ == "__main__":
try: try:
@ -10,7 +11,7 @@ if __name__ == "__main__":
print( print(
"Please make sure you have a installed towncrier and click before using this tool" "Please make sure you have a installed towncrier and click before using this tool"
) )
exit(1) sys.exit(1)
@click.command() @click.command()
@click.option( @click.option(

View File

@ -10,6 +10,7 @@ from subprocess import Popen, PIPE
from jinja2 import Environment, BaseLoader from jinja2 import Environment, BaseLoader
from requests import patch from requests import patch
import sys
import towncrier import towncrier
GIT_COMMANDS = { GIT_COMMANDS = {
@ -124,7 +125,7 @@ def _get_current_tag(git_command_name="get_tag"):
global GIT_COMMANDS global GIT_COMMANDS
command = GIT_COMMANDS.get(git_command_name) command = GIT_COMMANDS.get(git_command_name)
out, err, ret = _run_shell_command(command) out, err, ret = _run_shell_command(command)
if len(str(out)): if str(out):
return str(out).split("\n")[0] return str(out).split("\n")[0]
else: else:
return None return None
@ -178,7 +179,7 @@ def _update_release_version_for_sanic(
err.decode("utf-8") err.decode("utf-8")
) )
) )
exit(1) sys.exit(1)
def _generate_change_log(current_version: str = None): def _generate_change_log(current_version: str = None):
@ -186,13 +187,13 @@ def _generate_change_log(current_version: str = None):
command = GIT_COMMANDS.get("get_change_log") command = GIT_COMMANDS.get("get_change_log")
command[0] = command[0].format(current_version=current_version) command[0] = command[0].format(current_version=current_version)
output, error, ret = _run_shell_command(command=command) output, error, ret = _run_shell_command(command=command)
if not len(str(output)): if not str(output):
print("Unable to Fetch Change log details to update the Release Note") print("Unable to Fetch Change log details to update the Release Note")
exit(1) sys.exit(1)
commit_details = OrderedDict() commit_details = OrderedDict()
commit_details["authors"] = dict() commit_details["authors"] = {}
commit_details["commits"] = list() commit_details["commits"] = []
for line in str(output).split("\n"): for line in str(output).split("\n"):
commit, author, description = line.split(":::") commit, author, description = line.split(":::")
@ -228,7 +229,7 @@ def _tag_release(new_version, current_version, milestone, release_name, token):
out, error, ret = _run_shell_command(command=command) out, error, ret = _run_shell_command(command=command)
if int(ret) != 0: if int(ret) != 0:
print("Failed to execute the command: {}".format(command[0])) print("Failed to execute the command: {}".format(command[0]))
exit(1) sys.exit(1)
change_log = _generate_markdown_document( change_log = _generate_markdown_document(
milestone, release_name, current_version, new_version milestone, release_name, current_version, new_version
@ -256,7 +257,7 @@ def release(args: Namespace):
current_tag, current_version current_tag, current_version
) )
) )
exit(1) sys.exit(1)
new_version = args.release_version or _get_new_version( new_version = args.release_version or _get_new_version(
args.config, current_version, args.micro_release args.config, current_version, args.micro_release
) )
@ -348,6 +349,6 @@ if __name__ == "__main__":
}.items(): }.items():
if not value: if not value:
print(f"{key} is mandatory while using --tag-release") print(f"{key} is mandatory while using --tag-release")
exit(1) sys.exit(1)
with Directory(): with Directory():
release(args) release(args)

View File

@ -388,7 +388,7 @@ def test_bp_middleware_with_route(app):
def test_bp_middleware_order(app): def test_bp_middleware_order(app):
blueprint = Blueprint("test_bp_middleware_order") blueprint = Blueprint("test_bp_middleware_order")
order = list() order = []
@blueprint.middleware("request") @blueprint.middleware("request")
def mw_1(request): def mw_1(request):

View File

@ -83,7 +83,7 @@ argv = dict(
[ [
(dict(port=42102, auto_reload=True), "script"), (dict(port=42102, auto_reload=True), "script"),
(dict(port=42103, debug=True), "module"), (dict(port=42103, debug=True), "module"),
(dict(), "sanic"), ({}, "sanic"),
], ],
) )
async def test_reloader_live(runargs, mode): async def test_reloader_live(runargs, mode):

View File

@ -374,7 +374,7 @@ def test_file_head_response(app, file_name, static_file_directory):
file_path = os.path.join(static_file_directory, filename) file_path = os.path.join(static_file_directory, filename)
file_path = os.path.abspath(unquote(file_path)) file_path = os.path.abspath(unquote(file_path))
stats = await async_os.stat(file_path) stats = await async_os.stat(file_path)
headers = dict() headers = {}
headers["Accept-Ranges"] = "bytes" headers["Accept-Ranges"] = "bytes"
headers["Content-Length"] = str(stats.st_size) headers["Content-Length"] = str(stats.st_size)
if request.method == "HEAD": if request.method == "HEAD":
@ -450,7 +450,7 @@ def test_file_stream_head_response(app, file_name, static_file_directory):
async def file_route(request, filename): async def file_route(request, filename):
file_path = os.path.join(static_file_directory, filename) file_path = os.path.join(static_file_directory, filename)
file_path = os.path.abspath(unquote(file_path)) file_path = os.path.abspath(unquote(file_path))
headers = dict() headers = {}
headers["Accept-Ranges"] = "bytes" headers["Accept-Ranges"] = "bytes"
if request.method == "HEAD": if request.method == "HEAD":
# Return a normal HTTPResponse, not a # Return a normal HTTPResponse, not a

View File

@ -103,7 +103,7 @@ def test_static_file_bytes(app, static_file_directory, file_name):
@pytest.mark.parametrize( @pytest.mark.parametrize(
"file_name", "file_name",
[dict(), list(), object()], [{}, [], object()],
) )
def test_static_file_invalid_path(app, static_file_directory, file_name): def test_static_file_invalid_path(app, static_file_directory, file_name):
app.route("/")(lambda x: x) app.route("/")(lambda x: x)

View File

@ -2,7 +2,7 @@ import string
from urllib.parse import parse_qsl, urlsplit from urllib.parse import parse_qsl, urlsplit
import pytest as pytest import pytest
from sanic_testing.testing import HOST as test_host from sanic_testing.testing import HOST as test_host
from sanic_testing.testing import PORT as test_port from sanic_testing.testing import PORT as test_port

View File

@ -1,4 +1,4 @@
import pytest as pytest import pytest
from sanic.blueprints import Blueprint from sanic.blueprints import Blueprint
from sanic.constants import HTTP_METHODS from sanic.constants import HTTP_METHODS