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

Sourcery refactored master branch #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented Jan 20, 2022

Branch master refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the master branch, then run:

git fetch origin sourcery/master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from artemiszuk January 20, 2022 14:21
self.log.debug(f"serving finished")
self.log.debug('serving finished')
Copy link
Author

Choose a reason for hiding this comment

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

Function Client.download refactored with the following changes:

Comment on lines -12 to +18
text = "T"
if not favicon_path.exists():
W, H = (360, 360)
color = tuple((random.randint(0, 255) for _ in range(3)))
im = Image.new("RGB", (W, H), color)
draw = ImageDraw.Draw(im)
font = ImageFont.truetype("arial.ttf", 50)
text = "T"
Copy link
Author

Choose a reason for hiding this comment

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

Function FaviconIconView.faviconicon refactored with the following changes:

kwargs.update({"search": search_query})

kwargs["search"] = search_query
Copy link
Author

Choose a reason for hiding this comment

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

Function IndexView.index refactored with the following changes:

Comment on lines -40 to +50
if message.reply_markup:
if isinstance(message.reply_markup, types.ReplyInlineMarkup):
reply_btns = [
[
{"url": button.url, "text": button.text}
for button in button_row.buttons
if isinstance(button, types.KeyboardButtonUrl)
]
for button_row in message.reply_markup.rows
if message.reply_markup and isinstance(
message.reply_markup, types.ReplyInlineMarkup
):
reply_btns = [
[
{"url": button.url, "text": button.text}
for button in button_row.buttons
if isinstance(button, types.KeyboardButtonUrl)
]
for button_row in message.reply_markup.rows
]
Copy link
Author

Choose a reason for hiding this comment

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

Function InfoView.info refactored with the following changes:

pos = -1 if req.query.get("big", None) else int(len(photo.sizes) / 2)
pos = -1 if req.query.get("big", None) else len(photo.sizes) // 2
Copy link
Author

Choose a reason for hiding this comment

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

Function LogoView.logo refactored with the following changes:

Comment on lines -60 to +82
if request.app["is_authenticated"] and str(request.rel_url.path) not in [
if not request.app["is_authenticated"] or str(request.rel_url.path) in [
"/login",
"/logout",
]:
url = request.app.router["login_page"].url_for()
if str(request.rel_url) != "/":
url = url.with_query(redirect_to=str(request.rel_url))
return await handler(request)
url = request.app.router["login_page"].url_for()
if str(request.rel_url) != "/":
url = url.with_query(redirect_to=str(request.rel_url))

basic_auth_check_resp = _do_basic_auth_check(request)
basic_auth_check_resp = _do_basic_auth_check(request)

if basic_auth_check_resp is True:
return await handler(request)
if basic_auth_check_resp is True:
return await handler(request)

cookies_auth_check_resp = await _do_cookies_auth_check(request)
cookies_auth_check_resp = await _do_cookies_auth_check(request)

if cookies_auth_check_resp is not None:
return await handler(request)
if cookies_auth_check_resp is not None:
return await handler(request)

if isinstance(basic_auth_check_resp, Response):
return basic_auth_check_resp
if isinstance(basic_auth_check_resp, Response):
return basic_auth_check_resp

return HTTPFound(url)

return await handler(request)
return HTTPFound(url)
Copy link
Author

Choose a reason for hiding this comment

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

Function middleware_factory.factory refactored with the following changes:

Comment on lines -42 to +48
color = tuple([random.randint(0, 255) for i in range(3)])
color = tuple(random.randint(0, 255) for _ in range(3))
im = Image.new("RGB", (100, 100), color)
temp = io.BytesIO()
im.save(temp, "PNG")
body = temp.getvalue()
else:
thumb_pos = int(len(thumbnails) / 2)
thumb_pos = len(thumbnails) // 2
Copy link
Author

Choose a reason for hiding this comment

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

Function ThumbnailView.thumbnail_get refactored with the following changes:

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Jan 20, 2022

Sourcery Code Quality Report

✅  Merging this PR will increase code quality in the affected files by 2.11%.

Quality metrics Before After Change
Complexity 13.72 🙂 12.86 🙂 -0.86 👍
Method Length 111.72 🙂 111.11 🙂 -0.61 👍
Working memory 14.47 😞 13.91 😞 -0.56 👍
Quality 40.88% 😞 42.99% 😞 2.11% 👍
Other metrics Before After Change
Lines 530 524 -6
Changed files Quality Before Quality After Quality Change
app/telegram.py 50.05% 🙂 50.13% 🙂 0.08% 👍
app/views/faviconicon_view.py 61.14% 🙂 61.14% 🙂 0.00%
app/views/index_view.py 20.06% ⛔ 20.14% ⛔ 0.08% 👍
app/views/info_view.py 26.92% 😞 28.60% 😞 1.68% 👍
app/views/logo_view.py 36.48% 😞 36.57% 😞 0.09% 👍
app/views/middlewhere.py 62.86% 🙂 70.16% 🙂 7.30% 👍
app/views/thumbnail_view.py 37.32% 😞 37.42% 😞 0.10% 👍

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
app/views/index_view.py IndexView.index 23 😞 390 ⛔ 21 ⛔ 18.40% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
app/views/info_view.py InfoView.info 17 🙂 338 ⛔ 17 ⛔ 26.50% 😞 Try splitting into smaller methods. Extract out complex expressions
app/views/logo_view.py LogoView.logo 13 🙂 260 ⛔ 15 😞 34.54% 😞 Try splitting into smaller methods. Extract out complex expressions
app/views/thumbnail_view.py ThumbnailView.thumbnail_get 15 🙂 255 ⛔ 13 😞 35.76% 😞 Try splitting into smaller methods. Extract out complex expressions
app/telegram.py Client.download 7 ⭐ 173 😞 16 ⛔ 44.76% 😞 Try splitting into smaller methods. Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Help us improve this quality report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0 participants