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 Starbot ⭐ refactored enthyp/chat #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
8 changes: 3 additions & 5 deletions chat/chat_server/db/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,8 @@ def password_correct(self, nick, password):
log.err('DB: password_correct CALL SUCCESSFUL')
if correct_password:
return correct_password[0][0] == password
else:
log.err('DB: password_correct CALL FAILURE: no such user in database')
raise failure.Failure(sqlite3.IntegrityError())
log.err('DB: password_correct CALL FAILURE: no such user in database')
raise failure.Failure(sqlite3.IntegrityError())
Comment on lines -88 to +89
Copy link
Author

Choose a reason for hiding this comment

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

Function DBService.password_correct refactored with the following changes:

  • Remove unnecessary else after guard condition (remove-unnecessary-else)

except failure.Failure as f:
log.err(f'DB: password_correct FAILURE: {f.getErrorMessage()}')
raise
Expand Down Expand Up @@ -174,8 +173,7 @@ def add_notification(self, author, target, notification):
@log_operation
@defer.inlineCallbacks
def get_notifications(self, user):
results = yield self._dbpool.runQuery(query.select_notifications, (user,))
return results
return (yield self._dbpool.runQuery(query.select_notifications, (user,)))
Comment on lines -177 to +176
Copy link
Author

Choose a reason for hiding this comment

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

Function DBService.get_notifications refactored with the following changes:

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


@log_operation
def delete_notifications(self, user):
Expand Down
5 changes: 1 addition & 4 deletions chat/chat_server/dispatch/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ def remove_peer(self, peer, nick=None):
for c in self.channels.values():
c.unregister_user(nick)
elif isinstance(peer, ChatServer):
nicks = []
for k, v in self.user2peer.items():
if v == peer:
nicks.append(k)
nicks = [k for k, v in self.user2peer.items() if v == peer]
Copy link
Author

Choose a reason for hiding this comment

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

Function Dispatcher.remove_peer refactored with the following changes:

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

self.server_peers.remove(peer)
for n in nicks:
self.user2peer.pop(n, None)
Expand Down
1 change: 0 additions & 1 deletion chat/chat_server/peer/chat_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,6 @@ def msg_JOIN(self, message):
else:
if self.connected:
self.endpoint.no_channel(channel_name)
pass
Copy link
Author

Choose a reason for hiding this comment

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

Function LoggedInState.msg_JOIN refactored with the following changes:

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

except failure.Failure:
self.endpoint.internal_error('DB error, please try again.')

Expand Down
5 changes: 2 additions & 3 deletions chat/client/gui_qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,8 @@ def __init__(self, app, parent=None):
def send_message(self):
message = self.ui.plainTextEdit.toPlainText()
self.ui.textBrowser.append(message)
if message.strip(" ") != "":
if self.client:
self.client.handle_input(message.strip(" "))
if message.strip(" ") != "" and self.client:
self.client.handle_input(message.strip(" "))
Comment on lines -97 to +98
Copy link
Author

Choose a reason for hiding this comment

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

Function GUI.send_message refactored with the following changes:

  • Merge nested if conditions (merge-nested-ifs)

self.ui.plainTextEdit.clear()

def quit_channel(self):
Expand Down
3 changes: 1 addition & 2 deletions monitor/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

def connect_db():
"""Connects to the specific database."""
conn = sqlite3.connect(app.config['DATABASE'])
return conn
return sqlite3.connect(app.config['DATABASE'])
Copy link
Author

Choose a reason for hiding this comment

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

Function connect_db refactored with the following changes:

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



def init_db():
Expand Down
10 changes: 5 additions & 5 deletions monitor/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def extract_ratings(rows):

# extracts all channels from records and returns list
def extract_channels(rows):
return list(set([row[1] for row in rows]))
return list({row[1] for row in 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 extract_channels refactored with the following changes:

  • Replace unneeded comprehension with generator (comprehension-to-generator)
  • Replace list(), dict() or set() with comprehension (collection-builtin-to-comprehension)



@app.route('/', methods=['GET', 'POST'])
Expand Down Expand Up @@ -69,8 +69,8 @@ def history():
ratings_list = extract_ratings(rows)
channels_list = extract_channels(rows)

for i in range(0, len(ratings_list)):
for j in range(0, 6):
for i in range(len(ratings_list)):
for j in range(6):
Comment on lines -72 to +73
Copy link
Author

Choose a reason for hiding this comment

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

Function history refactored with the following changes:

  • Replace range(0, x) with range(x) (remove-zero-from-range)


if ratings_list[i][j] < 0.5:
ratings_list[i][j] = 0
Expand All @@ -95,8 +95,8 @@ def channel(name):
ratings_list = extract_ratings(rows)
channels_list = [name]

for i in range(0, len(ratings_list)):
for j in range(0, 6):
for i in range(len(ratings_list)):
for j in range(6):
Comment on lines -98 to +99
Copy link
Author

Choose a reason for hiding this comment

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

Function channel refactored with the following changes:

  • Replace range(0, x) with range(x) (remove-zero-from-range)


if ratings_list[i][j] < 0.5:
ratings_list[i][j] = 0
Expand Down