-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored main branch #1
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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] | ||
| print(result) | ||
|
|
||
| # Hover over the underlined code to see details of the changes including a diff. | ||
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| print(result) | ||
|
|
||
| # What if we don't want to make the change Sourcery suggests? | ||
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
|
|
||
| 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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
|
|
||
| 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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function
refactoring_examplerefactored with the following changes:list-comprehension)