Skip to content
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
2 changes: 1 addition & 1 deletion drum/links/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def order_by_score(queryset, score_fields, date_field, reverse=True):
else:
for obj in queryset:
age = (now() - getattr(obj, date_field)).total_seconds()
score_fields_sum = sum([getattr(obj, f) for f in score_fields])
score_fields_sum = sum(getattr(obj, f) for f in score_fields)
Copy link
Author

Choose a reason for hiding this comment

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

Function order_by_score refactored with the following changes:

  • Replace unneeded comprehension with generator (comprehension-to-generator)

score = score_fields_sum / pow(age, scale)
setattr(obj, "score", score)
return sorted(queryset, key=lambda obj: obj.score, reverse=reverse)
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@
])

finally:
for e in exclude:
if exclude[e] is not None:
for e, value in exclude.items():
if value is not None:
Comment on lines -80 to +81
Copy link
Author

Choose a reason for hiding this comment

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

Lines 80-81 refactored with the following changes:

  • Use items() to directly unpack dictionary values (use-dict-items)

data, stat = exclude[e]
try:
with open(e, "w") as f:
Expand Down