Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor code quality issues #2044

Merged
merged 1 commit into from
Mar 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .deepsource.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version = 1

test_patterns = ["tests/**"]

exclude_patterns = ["docker/**"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about the docs folder?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That can be excluded too, but I saw the conf.py file in there, so I didn't add the docs folder here.


[[analyzers]]
name = "python"
enabled = true

[analyzers.meta]
runtime_version = "3.x.x"
2 changes: 1 addition & 1 deletion sanic/mixins/listeners.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def _generate_next_value_(name: str, *args) -> str: # type: ignore

class ListenerMixin:
def __init__(self, *args, **kwargs) -> None:
self._future_listeners: List[FutureListener] = list()
self._future_listeners: List[FutureListener] = []

def _apply_listener(self, listener: FutureListener):
raise NotImplementedError # noqa
Expand Down
2 changes: 1 addition & 1 deletion sanic/mixins/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class MiddlewareMixin:
def __init__(self, *args, **kwargs) -> None:
self._future_middleware: List[FutureMiddleware] = list()
self._future_middleware: List[FutureMiddleware] = []

def _apply_middleware(self, middleware: FutureMiddleware):
raise NotImplementedError # noqa
Expand Down
2 changes: 1 addition & 1 deletion sanic/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ async def accept(self) -> None:
{
"type": "websocket.accept",
"subprotocol": ",".join(
[subprotocol for subprotocol in self.subprotocols]
list(self.subprotocols)
),
}
)
Expand Down
2 changes: 1 addition & 1 deletion sanic/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import sys
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.server import HttpProtocol, Signal, serve, trigger_events
Expand Down
3 changes: 2 additions & 1 deletion scripts/changelog.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python

from os import path
import sys

if __name__ == "__main__":
try:
Expand All @@ -10,7 +11,7 @@
print(
"Please make sure you have a installed towncrier and click before using this tool"
)
exit(1)
sys.exit(1)

@click.command()
@click.option(
Expand Down
19 changes: 10 additions & 9 deletions scripts/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from jinja2 import Environment, BaseLoader
from requests import patch
import sys
import towncrier

GIT_COMMANDS = {
Expand Down Expand Up @@ -124,7 +125,7 @@ def _get_current_tag(git_command_name="get_tag"):
global GIT_COMMANDS
command = GIT_COMMANDS.get(git_command_name)
out, err, ret = _run_shell_command(command)
if len(str(out)):
if str(out):
return str(out).split("\n")[0]
else:
return None
Expand Down Expand Up @@ -178,21 +179,21 @@ def _update_release_version_for_sanic(
err.decode("utf-8")
)
)
exit(1)
sys.exit(1)


def _generate_change_log(current_version: str = None):
global GIT_COMMANDS
command = GIT_COMMANDS.get("get_change_log")
command[0] = command[0].format(current_version=current_version)
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")
exit(1)
sys.exit(1)

commit_details = OrderedDict()
commit_details["authors"] = dict()
commit_details["commits"] = list()
commit_details["authors"] = {}
commit_details["commits"] = []

for line in str(output).split("\n"):
commit, author, description = line.split(":::")
Expand Down Expand Up @@ -228,7 +229,7 @@ def _tag_release(new_version, current_version, milestone, release_name, token):
out, error, ret = _run_shell_command(command=command)
if int(ret) != 0:
print("Failed to execute the command: {}".format(command[0]))
exit(1)
sys.exit(1)

change_log = _generate_markdown_document(
milestone, release_name, current_version, new_version
Expand Down Expand Up @@ -256,7 +257,7 @@ def release(args: Namespace):
current_tag, current_version
)
)
exit(1)
sys.exit(1)
new_version = args.release_version or _get_new_version(
args.config, current_version, args.micro_release
)
Expand Down Expand Up @@ -348,6 +349,6 @@ def release(args: Namespace):
}.items():
if not value:
print(f"{key} is mandatory while using --tag-release")
exit(1)
sys.exit(1)
with Directory():
release(args)
2 changes: 1 addition & 1 deletion tests/test_blueprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ async def bp_handler(request):

def test_bp_middleware_order(app):
blueprint = Blueprint("test_bp_middleware_order")
order = list()
order = []

@blueprint.middleware("request")
def mw_1(request):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_reloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def scanner(proc):
[
(dict(port=42102, auto_reload=True), "script"),
(dict(port=42103, debug=True), "module"),
(dict(), "sanic"),
({}, "sanic"),
],
)
async def test_reloader_live(runargs, mode):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ async def file_route(request, filename):
file_path = os.path.join(static_file_directory, filename)
file_path = os.path.abspath(unquote(file_path))
stats = await async_os.stat(file_path)
headers = dict()
headers = {}
headers["Accept-Ranges"] = "bytes"
headers["Content-Length"] = str(stats.st_size)
if request.method == "HEAD":
Expand Down Expand Up @@ -450,7 +450,7 @@ def test_file_stream_head_response(app, file_name, static_file_directory):
async def file_route(request, filename):
file_path = os.path.join(static_file_directory, filename)
file_path = os.path.abspath(unquote(file_path))
headers = dict()
headers = {}
headers["Accept-Ranges"] = "bytes"
if request.method == "HEAD":
# Return a normal HTTPResponse, not a
Expand Down
2 changes: 1 addition & 1 deletion tests/test_static.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def test_static_file_bytes(app, static_file_directory, file_name):

@pytest.mark.parametrize(
"file_name",
[dict(), list(), object()],
[{}, [], object()],
)
def test_static_file_invalid_path(app, static_file_directory, file_name):
app.route("/")(lambda x: x)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_url_building.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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 PORT as test_port
Expand Down
2 changes: 1 addition & 1 deletion tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import pytest as pytest
import pytest

from sanic.blueprints import Blueprint
from sanic.constants import HTTP_METHODS
Expand Down