Skip to content

Conversation

@sourcery-ai
Copy link

@sourcery-ai sourcery-ai bot commented Jun 5, 2020

Branch master refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

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

git fetch origin sourcery/master
git merge --ff-only FETCH_HEAD
git reset HEAD^

checkout_commit(commit.hash)
all_wordcounts[commit] = get_wordcounts()
filenames.update(set(wc.filename for wc in all_wordcounts[commit]))
filenames.update({wc.filename for wc in all_wordcounts[commit]})
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:

  • Merge dictionary assignment with declaration
  • Replace list(), dict() or set() with comprehension

fixed_row[field] = val
else:
fixed_row[field] = 0
fixed_row[field] = val if val else 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 get_data_from_csv refactored with the following changes:

  • Replace if statement with if expression

ROMAN_NUMERALS = ('I', 'V', 'X')
def add(augend, addend):
if not isinstance(augend, basestring) or not isinstance(addend, basestring):
if not (isinstance(augend, basestring) and isinstance(addend, basestring)):
Copy link
Author

Choose a reason for hiding this comment

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

Function add refactored with the following changes:

  • Inline variable that is only used once
  • Simplify logical expression

else:
output_before = ''

output_before = fix_newlines(output_before.strip()) if output_before 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 parse_output refactored with the following changes:

  • Replace if statement with if expression

Comment on lines -45 to +46
inseq[pos:pos + len(subseq)] == subseq
for pos in range(0, len(inseq) - len(subseq) + 1)
inseq[pos : pos + len(subseq)] == subseq
for pos in range(len(inseq) - len(subseq) + 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 contains refactored with the following changes:

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

print(output)
except io.BlockingIOError as e:
print(e)
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 SourceTree.run_command refactored with the following changes:

  • Remove redundant pass statement

Comment on lines -644 to +645
actual2 = "AssertionError: something"
with self.assertRaises(AssertionError):
actual2 = "AssertionError: something"
Copy link
Author

Choose a reason for hiding this comment

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

Function AssertConsoleOutputCorrectTest.test_ignores_3_5_x_AssertionError_None_thing refactored with the following changes:

  • Move assignments closer to their usage

Comment on lines -665 to +667
actual = "qnslckvp2aga7tm6xuivyb0ob1akzzwl"
expected = Output("jvhzc8kj2mkh06xooqq9iciptead20qq")
with self.assertRaises(AssertionError):
actual = "qnslckvp2aga7tm6xuivyb0ob1akzzwl"
Copy link
Author

Choose a reason for hiding this comment

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

Function AssertConsoleOutputCorrectTest.test_only_ignores_exactly_32_char_strings_no_whitespace refactored with the following changes:

  • Move assignments closer to their usage


self.start_with_checkout()

vm_restore = 'MAKING_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 Chapter9cTest.test_listings_and_commands_and_output refactored with the following changes:

  • Move assignments closer to their usage

Comment on lines -43 to -44
vm_restore = 'MANUAL_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 Chapter9bTest.test_listings_and_commands_and_output refactored with the following changes:

  • Move assignments closer to their usage

Comment on lines -38 to -39
vm_restore = 'FABRIC_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 Chapter18Test.test_listings_and_commands_and_output refactored with the following changes:

  • Move assignments closer to their usage

assert source.find_start_line(['indented', 'whatever']) == 4
assert source.find_start_line([' indented', 'whatever']) == 4
assert source.find_start_line(['no such line', 'whatever']) == None
assert source.find_start_line(['no such line', 'whatever']) is None
Copy link
Author

Choose a reason for hiding this comment

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

Function LineFindingTests.test_finding_start_line refactored with the following changes:

  • Use x is None rather than x == None

Comment on lines -669 to +670
assert source.find_end_line(['bla bla', 'whatever']) == None
assert source.find_end_line(['no such line', 'whatever']) == None
assert source.find_end_line(['bla bla', 'whatever']) is None
assert source.find_end_line(['no such line', 'whatever']) is None
Copy link
Author

Choose a reason for hiding this comment

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

Function LineFindingTests.test_finding_end_line refactored with the following changes:

  • Use x is None rather than x == None

Comment on lines -740 to +750
lines = [
"def method1(self):",
" # amend method 1",
" return 2",
]
future_lines = [
" def method1(self):",
" # amend method 1",
" return 2",
]
with self.assertRaises(ApplyCommitException):
lines = [
"def method1(self):",
" # amend method 1",
" return 2",
]
future_lines = [
" def method1(self):",
" # amend method 1",
" return 2",
]
Copy link
Author

Choose a reason for hiding this comment

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

Function CheckIndentationTest.test_over_indentation_differences_are_picked_up refactored with the following changes:

  • Move assignments closer to their usage

Comment on lines -755 to +765
lines = [
"def method1(self):",
"# amend method 1",
" return 2",
]
future_lines = [
" def method1(self):",
" # amend method 1",
" return 2",
]
with self.assertRaises(ApplyCommitException):
lines = [
"def method1(self):",
"# amend method 1",
" return 2",
]
future_lines = [
" def method1(self):",
" # amend method 1",
" return 2",
]
Copy link
Author

Choose a reason for hiding this comment

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

Function CheckIndentationTest.test_under_indentation_differences_are_picked_up refactored with the following changes:

  • Move assignments closer to their usage

Comment on lines -77 to +74
new_content = '\n'.join(old_lines).replace(likely_line, new_line)
return new_content
return '\n'.join(old_lines).replace(likely_line, new_line)
Copy link
Author

Choose a reason for hiding this comment

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

Function _replace_single_line refactored with the following changes:

  • Inline variable that is only used once

view_name = VIEW_FINDER.search(new_lines[0]).group(1)
if view_name in source.views:
return source.replace_function(new_lines)
return '\n'.join(old_lines) + '\n\n' + '\n'.join(new_lines)
Copy link
Author

Choose a reason for hiding this comment

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

Function _replace_lines_in refactored with the following changes:

  • Merge nested if conditions

Comment on lines -143 to -146
last_line_in_our_class = max(
return max(
getattr(thing, 'lineno', 0) for thing in ast.walk(our_class)
)
return last_line_in_our_class
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_last_line_for_class refactored with the following changes:

  • Inline variable that is only used once

POSSIBLE_PATH = []

if sys.platform == "linux" or sys.platform == "linux2" or sys.platform == "darwin":
if sys.platform in ["linux", "linux2", "darwin"]:
Copy link
Author

Choose a reason for hiding this comment

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

Lines 42-42 refactored with the following changes:

  • Replace multiple comparisons of same variable with in operator

]
for arg in SYS_ARGS:
if arg == '--help' or arg == "-h":
if arg in ['--help', "-h"]:
Copy link
Author

Choose a reason for hiding this comment

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

Lines 142-193 refactored with the following changes:

  • Merge extend into list assignment
  • Replace multiple comparisons of same variable with in operator

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.

2 participants