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 akkana/scripts #11

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

Conversation

SourceryAI
Copy link

Thanks for starring sourcery-ai/sourcery ✨ 🌟 ✨

Here's your pull request refactoring your most popular Python repo.

If you want Sourcery to refactor all your Python repos and incoming pull requests install our bot.

Review changes via command line

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

git fetch https://github.com/sourcery-ai-bot/scripts master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Copy link
Author

@SourceryAI SourceryAI left a comment

Choose a reason for hiding this comment

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

Due to GitHub API limits, only the first 60 comments can be shown.

Comment on lines -43 to +49
if self.lunar:
self.sun = ephem.Moon()
else:
self.sun = ephem.Sun()
self.sun = ephem.Moon() if self.lunar else ephem.Sun()
self.sinusoidal = False

self.sun_color = (1, 1, 0)
self.backside_color = (1, .7, 0)
self.text_color = (1, 1, 0)
if background:
self.background_color = background
else:
self.background_color = (0, 0, .6, 1)
self.background_color = background if background else (0, 0, .6, 1)
Copy link
Author

Choose a reason for hiding this comment

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

Function AnalemmaWindow.__init__ refactored with the following changes:

  • Replace if statement with if expression

Comment on lines -401 to +395
for f in range(0, int(math.pi * 100)):
for f in range(int(math.pi * 100)):
Copy link
Author

Choose a reason for hiding this comment

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

Function AnalemmaWindow.draw refactored with the following changes:

  • Replace range(0, x) with range(x)
  • Replace unused for index with underscore

Comment on lines -151 to +153
lenpath = len(path)
if recursive:
file_list = []
lenpath = len(path)
Copy link
Author

Choose a reason for hiding this comment

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

Function list_local_dir refactored with the following changes:

  • Move assignments closer to their usage

if not is_android(src) and not is_android(dst):
if not (is_android(src) or is_android(dst)):
Copy link
Author

Choose a reason for hiding this comment

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

Function copyfile refactored with the following changes:

  • Simplify logical expression

Comment on lines -302 to +304
if os.path.basename(p[0]) == base:
if p[1] == pair[1]:
match = i
num_matches += 1
if os.path.basename(p[0]) == base and p[1] == pair[1]:
match = i
num_matches += 1
Copy link
Author

Choose a reason for hiding this comment

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

Function find_basename_size_match refactored with the following changes:

  • Merge nested if conditions

Comment on lines -226 to +223
if hour > 12:
hourstr = str(hour-12) + " pm"
else:
hourstr = str(hour) + " am"

hourstr = str(hour-12) + " pm" if hour > 12 else str(hour) + " am"
Copy link
Author

Choose a reason for hiding this comment

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

Function Conjunction.closeout.conjstr refactored with the following changes:

  • Replace if statement with if expression

Comment on lines -353 to +347
if transit[3] < 3 or transit[3] > 12:
when = "evening"
else:
when = "morning"

if p == "Venus" or p == "Mercury":
when = "evening" if transit[3] < 3 or transit[3] > 12 else "morning"
if p in ["Venus", "Mercury"]:
Copy link
Author

Choose a reason for hiding this comment

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

Function finish_planet refactored with the following changes:

  • Replace if statement with if expression
  • Replace multiple comparisons of same variable with in operator
  • Simplify conditional into switch-like form
  • Split conditional into multiple branches
  • Merge duplicate blocks in conditional
  • Remove redundant conditional
  • Remove empty elif clause
  • Simplify logical expression

elif on_vowel and not in_diphthong and c != lastchar:
elif not in_diphthong and c != lastchar:
Copy link
Author

Choose a reason for hiding this comment

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

Function count_syllables refactored with the following changes:

  • Remove redundant conditional

if type(part[0]) is bytes:
ret += part[0].decode(errors='replace')
else:
ret += part[0]

ret += part[0].decode(errors='replace') if type(part[0]) is bytes else part[0]
Copy link
Author

Choose a reason for hiding this comment

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

Function decode_piece refactored with the following changes:

  • Replace if statement with if expression

Comment on lines -162 to +158
if sys.argv[1] == '-h' or sys.argv[1] == '--help':
if sys.argv[1] in ['-h', '--help']:
Copy link
Author

Choose a reason for hiding this comment

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

Lines 162-162 refactored with the following changes:

  • Replace multiple comparisons of same variable with in operator

Comment on lines -24 to +26
for i in range(RETRIES):
for _ in range(RETRIES):
try:
domain = whois.whois(name)
return domain
return whois.whois(name)
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_domain refactored with the following changes:

  • Inline variable that is only used once
  • Replace unused for index with underscore

Comment on lines -66 to +65
if d[1] < two_months_from_now:
alert = "***"
else:
alert = ""
alert = "***" if d[1] < two_months_from_now else ""
Copy link
Author

Choose a reason for hiding this comment

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

Lines 66-69 refactored with the following changes:

  • Replace if statement with if expression

if len(sys.argv) > 2:
message = ' '.join(sys.argv[2:])
else:
message = "Wake up!"

message = ' '.join(sys.argv[2:]) if len(sys.argv) > 2 else "Wake up!"
Copy link
Author

Choose a reason for hiding this comment

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

Lines 68-72 refactored with the following changes:

  • Replace if statement with if expression

Comment on lines -59 to -60
return

Copy link
Author

Choose a reason for hiding this comment

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

Function EpubBook.parse_contents refactored with the following changes:

  • Remove unreachable code

Comment on lines -183 to +181
if len(authors) > 1:
outstr += "Authors: "
else:
outstr += "Author: "
outstr += "Authors: " if len(authors) > 1 else "Author: "
Copy link
Author

Choose a reason for hiding this comment

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

Function EpubBook.info_string refactored with the following changes:

  • Replace if statement with if expression

for pat in orpats:
if pat in tags:
return True
return False
return any(pat in tags for pat in orpats)
Copy link
Author

Choose a reason for hiding this comment

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

Function has_match refactored with the following changes:

  • Use any() instead of for loop

legend_patches = []
for c in colormap:
legend_patches.append(mpatches.Patch(color=colormap[c], label=c))
legend_patches = [mpatches.Patch(color=colormap[c], label=c) for c in colormap]
Copy link
Author

Choose a reason for hiding this comment

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

Lines 53-55 refactored with the following changes:

  • Convert for loop into list comprehension

for branch in localbranches:
lb = localbranches[branch]
for branch, lb in localbranches.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 list_branches refactored with the following changes:

  • Use items() to directly unpack dictionary values

Comment on lines -283 to +282
if not args.list and not args.check and not args.track:
if not (args.list or args.check or args.track):
Copy link
Author

Choose a reason for hiding this comment

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

Function main refactored with the following changes:

  • Simplify logical expression

if not (web_view.get_zoom_level() == 1.0):
if web_view.get_zoom_level() != 1.0:
Copy link
Author

Choose a reason for hiding this comment

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

Function WebToolbar.zoom_hundred_cb refactored with the following changes:

  • Simplify logical expression

if not tcurrent or (not tmax and not tcrit):
if not (tcurrent and (tmax or tcrit)):
Copy link
Author

Choose a reason for hiding this comment

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

Function fetch_temps refactored with the following changes:

  • Simplify logical expression

for quad in temps:
if quad[1] > quad[2]:
return True
return False
return any(quad[1] > quad[2] for quad in temps)
Copy link
Author

Choose a reason for hiding this comment

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

Function overtemp refactored with the following changes:

  • Use any() instead of for loop

return not all(ord(c) < 128 for c in s)
return any(ord(c) >= 128 for c in s)
Copy link
Author

Choose a reason for hiding this comment

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

Function contains_non_ascii_characters refactored with the following changes:

  • Simplify inverted any() and all() calls

if event.string == "q":
elif event.string == "q":
Copy link
Author

Choose a reason for hiding this comment

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

Function key_press_event refactored with the following changes:

  • Simplify conditional into switch-like form

Comment on lines -41 to +56
if True:
rect = self.get_allocation()
w = rect.width
h = rect.height
if w != self.width or h != self.height:
# get_allocation() gives a number that's too large,
# and if we later try to draw_rectangle() with these
# dimensions, we'll only get half the rectangle horizontally.
# I have no idea why this is happening, but subtracting a
# few pixels from allocation width is a temporary workaround.
self.width = w # -5
self.height = h

# Have we had load_image called, but we weren't ready for it?
# Now, theoretically, we are ... so call it again.
if w and h and self.cur_img and not self.pixbuf:
self.prepare_image()
rect = self.get_allocation()
w = rect.width
h = rect.height
if w != self.width or h != self.height:
# get_allocation() gives a number that's too large,
# and if we later try to draw_rectangle() with these
# dimensions, we'll only get half the rectangle horizontally.
# I have no idea why this is happening, but subtracting a
# few pixels from allocation width is a temporary workaround.
self.width = w # -5
self.height = h

# Have we had load_image called, but we weren't ready for it?
# Now, theoretically, we are ... so call it again.
if w and h and self.cur_img and not self.pixbuf:
self.prepare_image()
Copy link
Author

Choose a reason for hiding this comment

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

Function ImageViewer.draw refactored with the following changes:

  • Remove redundant conditional

if e.key == 'ctrl+q' or e.key == 'q':
if e.key in ['ctrl+q', 'q']:
Copy link
Author

Choose a reason for hiding this comment

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

Function key_press refactored with the following changes:

  • Replace multiple comparisons of same variable with in operator

active = []
for mname in self.monitors:
if mname in self.mon_geom:
active.append(mname)
return active
return [mname for mname in self.monitors if mname in self.mon_geom]
Copy link
Author

Choose a reason for hiding this comment

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

Function MonMon.active_monitors refactored with the following changes:

  • Convert for loop into list comprehension
  • Inline variable that is only used once

Comment on lines -125 to +121
inactive = []
for mname in self.monitors:
if mname not in self.mon_geom:
inactive.append(mname)
return inactive
return [mname for mname in self.monitors if mname not in self.mon_geom]
Copy link
Author

Choose a reason for hiding this comment

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

Function MonMon.inactive_monitors refactored with the following changes:

  • Convert for loop into list comprehension
  • Inline variable that is only used once

Comment on lines -144 to +136
if self.laptop_screen == mon['name']:
islaptop = " **laptop"
else:
islaptop = ""
islaptop = " **laptop" if self.laptop_screen == mon['name'] else ""
Copy link
Author

Choose a reason for hiding this comment

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

Function MonMon.print_monitor refactored with the following changes:

  • Replace if statement with if expression

return list(range(start, max)) + list(range(0, end))
return list(range(start, max)) + list(range(end))
Copy link
Author

Choose a reason for hiding this comment

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

Function discont_range refactored with the following changes:

  • Replace range(0, x) with range(x)

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