Skip to content
Open
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
29 changes: 7 additions & 22 deletions welcome-to-sourcery.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
# This means Sourcery has a suggestion.

def refactoring_example(spellbook):
result = []
for spell in spellbook:
if spell.is_awesome:
result.append(spell)
result = [spell for spell in spellbook if spell.is_awesome]
Copy link
Author

Choose a reason for hiding this comment

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

Function refactoring_example refactored with the following changes:

print(result)

# Hover over the underlined code to see details of the changes including a diff.
Expand All @@ -27,11 +24,9 @@ def refactoring_example(spellbook):
# code quality - hover over the function definition below to see this report.

def magical_hoist(magic):
if is_powerful(magic):
result = 'Magic'
else:
if not is_powerful(magic):
print("Not powerful.")
result = 'Magic'
result = 'Magic'
Comment on lines -30 to +29
Copy link
Author

Choose a reason for hiding this comment

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

Function magical_hoist refactored with the following changes:

print(result)

# What if we don't want to make the change Sourcery suggests?
Expand Down Expand Up @@ -72,23 +67,13 @@ def magical_hoist(magic):
# up with more powerful refactorings.

def find_more(magicks):
powerful_magic = []
for magic in magicks:
if not is_powerful(magic):
continue
powerful_magic.append(magic)
return powerful_magic
return [magic for magic in magicks if is_powerful(magic)]
Comment on lines -75 to +70
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_more refactored with the following changes:



def is_powerful(magic):
if magic == 'Sourcery':
return True
elif magic == 'More Sourcery':
return True
else:
return False
return magic in ['Sourcery', 'More Sourcery']
Comment on lines -84 to +74
Copy link
Author

Choose a reason for hiding this comment

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

Function is_powerful refactored with the following changes:



def print_all(spells: list):
for i in range(len(spells)):
print(spells[i])
for spell in spells:
print(spell)
Comment on lines -93 to +79
Copy link
Author

Choose a reason for hiding this comment

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

Function print_all refactored with the following changes: