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 Mar 10, 2023

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 ramanveerji March 10, 2023 19:15
Comment on lines -46 to -53
chat: Preference = (
if chat := (
session.query(Preference).filter(Preference.user_id == user_id).first()
)
if not chat:
):
chat.language = language
else:
chat = Preference(user_id=user_id, language=language)
session.add(chat)
else:
chat.language = language
Copy link
Author

Choose a reason for hiding this comment

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

Function update_language refactored with the following changes:

Comment on lines -52 to +57
"Broadcasting completed! Message was sent to {} chats\n".format(
sent_successfully
),
f"Broadcasting completed! Message was sent to {sent_successfully} chats\n",
lang,
)
if failed_to_send:
broadcast_status_message += _(
"Failed to broadcast to {} chats, most likely because bot has been stopped or kicked out.".format(
failed_to_send
),
f"Failed to broadcast to {failed_to_send} chats, most likely because bot has been stopped or kicked out.",
Copy link
Author

Choose a reason for hiding this comment

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

Function broadcast_handler refactored with the following changes:

Comment on lines -18 to +20
await event.respond(message, buttons=buttons) if not hasattr(
await event.edit(message, buttons=buttons) if hasattr(
event, "data"
) else await event.edit(message, buttons=buttons)
) else await event.respond(message, buttons=buttons)
Copy link
Author

Choose a reason for hiding this comment

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

Function preferences_handler refactored with the following changes:

with open(f"restart.pickle", "wb") as out:
with open("restart.pickle", "wb") as out:
Copy link
Author

Choose a reason for hiding this comment

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

Function restart refactored with the following changes:

Comment on lines -30 to +37
output_formats_message = ""
for output_format, count in output_formats.items():
output_formats_message += f" __{output_format}__: {str(count)} times.\n"
input_formats_message = ""
for input_format, count in input_formats.items():
input_formats_message += f" __{input_format}__: {str(count)} times.\n"
output_formats_message = "".join(
f" __{output_format}__: {str(count)} times.\n"
for output_format, count in output_formats.items()
)
input_formats_message = "".join(
f" __{input_format}__: {str(count)} times.\n"
for input_format, count in input_formats.items()
)
Copy link
Author

Choose a reason for hiding this comment

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

Function stats refactored with the following changes:

  • Use str.join() instead of for loop [×2] (use-join)

Comment on lines -21 to +23
with ZipFile(input_file) as book, ZipFile(
f"{input_file}_", "w", compression=ZIP_DEFLATED
) as out:
with (ZipFile(input_file) as book, ZipFile(
f"{input_file}_", "w", compression=ZIP_DEFLATED
) as out):
Copy link
Author

Choose a reason for hiding this comment

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

Function fix_content_opf_problems refactored with the following changes:

name += " " + event.chat.last_name.strip()
name += f" {event.chat.last_name.strip()}"
Copy link
Author

Choose a reason for hiding this comment

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

Function get_chat_name refactored with the following changes:

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Mar 10, 2023

Sourcery Code Quality Report

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

Quality metrics Before After Change
Complexity 3.44 ⭐ 3.34 ⭐ -0.10 👍
Method Length 65.67 🙂 65.63 🙂 -0.04 👍
Working memory 8.12 🙂 8.01 🙂 -0.11 👍
Quality 70.73% 🙂 71.14% 🙂 0.41% 👍
Other metrics Before After Change
Lines 334 331 -3
Changed files Quality Before Quality After Quality Change
ebook_converter_bot/db/curd.py 83.86% ⭐ 83.68% ⭐ -0.18% 👎
ebook_converter_bot/modules/broadcast.py 63.77% 🙂 63.77% 🙂 0.00%
ebook_converter_bot/modules/preferences.py 75.38% ⭐ 75.43% ⭐ 0.05% 👍
ebook_converter_bot/modules/restart.py 87.48% ⭐ 87.63% ⭐ 0.15% 👍
ebook_converter_bot/modules/stats.py 55.29% 🙂 56.84% 🙂 1.55% 👍
ebook_converter_bot/utils/epub.py 51.12% 🙂 51.21% 🙂 0.09% 👍
ebook_converter_bot/utils/telegram.py 77.65% ⭐ 77.59% ⭐ -0.06% 👎

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

File Function Complexity Length Working Memory Quality Recommendation
ebook_converter_bot/utils/epub.py fix_content_opf_problems 10 🙂 230 ⛔ 15 😞 38.80% 😞 Try splitting into smaller methods. Extract out complex expressions
ebook_converter_bot/modules/stats.py stats 0 ⭐ 145 😞 14 😞 56.84% 🙂 Try splitting into smaller methods. Extract out complex expressions
ebook_converter_bot/modules/broadcast.py broadcast_handler 5 ⭐ 136 😞 8 🙂 63.77% 🙂 Try splitting into smaller methods
ebook_converter_bot/modules/preferences.py update_language_callback 0 ⭐ 94 🙂 11 😞 67.94% 🙂 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