Skip to content

Sourcery refactored master branch - #1

Open
sourcery-ai[bot] wants to merge 1 commit into
masterfrom
sourcery/master
Open

sourcery-ai[bot] wants to merge 1 commit into
masterfrom
sourcery/master

Conversation

@sourcery-ai

@sourcery-ai sourcery-ai Bot commented Jun 30, 2020

Copy link
Copy Markdown

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^

Comment thread examples/step_example.py
sex = message.text
user = user_dict[chat_id]
if (sex == u'Male') or (sex == u'Female'):
if sex in [u'Male', u'Female']:

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function process_sex_step refactored with the following changes:

  • Replace multiple comparisons of same variable with in operator (merge-comparisons)

Comment on lines -56 to +59
self.finish()
else:
self.write("What are you doing here?")
self.finish()

self.finish()

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function webhook_serv.post refactored with the following changes:

  • Hoist repeated code outside conditional statement (hoist-statement-from-if)

Comment thread telebot/__init__.py
Comment on lines -315 to +331
if len(new_messages) > 0:
if new_messages:
self.process_new_messages(new_messages)
if len(edited_new_messages) > 0:
if edited_new_messages:
self.process_new_edited_messages(edited_new_messages)
if len(new_channel_posts) > 0:
if new_channel_posts:
self.process_new_channel_posts(new_channel_posts)
if len(new_edited_channel_posts) > 0:
if new_edited_channel_posts:
self.process_new_edited_channel_posts(new_edited_channel_posts)
if len(new_inline_querys) > 0:
if new_inline_querys:
self.process_new_inline_query(new_inline_querys)
if len(new_chosen_inline_results) > 0:
if new_chosen_inline_results:
self.process_new_chosen_inline_query(new_chosen_inline_results)
if len(new_callback_querys) > 0:
if new_callback_querys:
self.process_new_callback_query(new_callback_querys)
if len(new_pre_checkout_querys) > 0:
if new_pre_checkout_querys:
self.process_new_pre_checkout_query(new_pre_checkout_querys)
if len(new_shipping_querys) > 0:
if new_shipping_querys:

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function TeleBot.process_new_updates refactored with the following changes:

  • Simplify sequence comparison (simplify-len-comparison)

Comment thread telebot/__init__.py
self.polling(timeout=timeout, *args, **kwargs)
except Exception as e:
time.sleep(timeout)
pass

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function TeleBot.infinity_polling refactored with the following changes:

  • Remove redundant pass statement (remove-redundant-pass)

Comment thread telebot/__init__.py
Comment on lines -520 to +519
result = apihelper.leave_chat(self.token, chat_id)
return result
return apihelper.leave_chat(self.token, chat_id)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function TeleBot.leave_chat refactored with the following changes:

  • Inline variable that is immediately returned (inline-immediately-returned-variable)

Comment thread telebot/types.py
Comment on lines -871 to +860
btn_array = []
for button in args:
btn_array.append(button.to_dic())
btn_array = [button.to_dic() for button in args]

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function InlineKeyboardMarkup.row refactored with the following changes:

  • Convert for loop into list comprehension (list-comprehension)

Comment thread telebot/types.py
Comment on lines -887 to +874
json_dict = {'inline_keyboard': self.keyboard}
return json_dict
return {'inline_keyboard': self.keyboard}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function InlineKeyboardMarkup.to_dic refactored with the following changes:

  • Inline variable that is immediately returned (inline-immediately-returned-variable)

Comment thread telebot/types.py
Comment on lines -1789 to +1775
ret = []
for ps in photo_size_array:
ret.append(PhotoSize.de_json(ps))
return ret
return [PhotoSize.de_json(ps) for ps in photo_size_array]

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function Game.parse_photo refactored with the following changes:

  • Convert for loop into list comprehension (list-comprehension)
  • Inline variable that is immediately returned (inline-immediately-returned-variable)

Comment thread telebot/types.py
Comment on lines -1796 to +1779
ret = []
for me in message_entity_array:
ret.append(MessageEntity.de_json(me))
return ret
return [MessageEntity.de_json(me) for me in message_entity_array]

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function Game.parse_entities refactored with the following changes:

  • Convert for loop into list comprehension (list-comprehension)
  • Inline variable that is immediately returned (inline-immediately-returned-variable)

Comment thread telebot/types.py
Comment on lines -1934 to +1915
price_list = []
for p in self.prices:
price_list.append(p.to_dic())
json_dict = json.dumps({'id': self.id, 'title': self.title, 'prices': price_list})
return json_dict
price_list = [p.to_dic() for p in self.prices]
return json.dumps({'id': self.id, 'title': self.title, 'prices': price_list})

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function ShippingOption.to_json refactored with the following changes:

  • Inline variable that is immediately returned (inline-immediately-returned-variable)
  • Convert for loop into list comprehension (list-comprehension)

Comment thread telebot/types.py
Comment on lines -2122 to +2099
ret = super(InputMediaPhoto, self).to_dic()
return ret
return super(InputMediaPhoto, self).to_dic()

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function InputMediaPhoto.to_dic refactored with the following changes:

  • Inline variable that is immediately returned (inline-immediately-returned-variable)

@sourcery-ai

sourcery-ai Bot commented Jun 30, 2020

Copy link
Copy Markdown
Author

Sourcery Code Quality Report (beta)

✅ Merging this PR will increase code quality in the affected files by 0.01 out of 10.

Before After Change
Quality 9.05 9.06 0.01
Complexity 0.99 0.97 -0.02
Method Length 37.11 36.81 -0.29
Lines 3602 3573 -29
Changed files Quality Before Quality After Quality Change
examples/step_example.py 8.97 9.0 0.02 ⬆️
examples/webhook_examples/webhook_tornado_echo_bot.py 9.18 9.19 0.01 ⬆️
telebot/init.py 9.32 9.32 0.0 ⬆️
telebot/types.py 8.72 8.73 0.01 ⬆️

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

File Function Quality Recommendation
telebot/types.py Message.de_json 1.52 Reduce complexity. Split out functionality
telebot/init.py TeleBot.process_new_updates 3.51 Split out functionality
telebot/types.py Message.__html_text 4.72 Split out functionality
telebot/types.py Update.de_json 5.58 Split out functionality
telebot/init.py TeleBot.__threaded_polling 6.0 Split out functionality

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!

Let us know what you think of it via email or our Gitter!

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.

1 participant