Skip to content

Sourcery refactored master branch#2

Open
sourcery-ai[bot] wants to merge 1 commit into
masterfrom
sourcery/master
Open

Sourcery refactored master branch#2
sourcery-ai[bot] wants to merge 1 commit into
masterfrom
sourcery/master

Conversation

@sourcery-ai
Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot commented Jun 28, 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^

Comment thread TwitterSearch/setup.py
for line in open('requirements.txt','r'):
req.append(line.split()[0])
return req
return [line.split()[0] for line in open('requirements.txt','r')]
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function requirements refactored with the following changes:

  • Convert for loop into list comprehension (list-comprehension)
  • Inline variable that is immediately returned (inline-immediately-returned-variable)

"""
results = TwitterSearchResults(self.search_tweets(order))
return results
return TwitterSearchResults(self.search_tweets(order))
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function TwitterSearch.getSearchResults refactored with the following changes:

  • Inline variable that is immediately returned (inline-immediately-returned-variable)

self.message = msg
else:
self.message = self._error_codes.get(code)
self.message = msg if msg else self._error_codes.get(code)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function TwitterSearchException.__init__ refactored with the following changes:

  • Replace if statement with if expression (assign-if-exp)

f = open(filename, 'r')
for line in f:
yield line
yield from f
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function TwitterSearchTest.apiAnsweringMachine refactored with the following changes:

  • Replace yield inside for loop with yield from (yield-from)

Comment on lines -119 to +118
for tweet in ts.search_tweets_iterable(tuo):
for _ in ts.search_tweets_iterable(tuo):
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function TwitterSearchTest.test_TS_search_usertimeline_iterable refactored with the following changes:

  • Replace unused for index with underscore (for-index-underscore)

self.assertTrue(False, "Not raising exception for lat %s, lon %s, radius %s and metric %s" % (value,value,radius,unit))
except TwitterSearchException as e:
self.assertTrue((e.code == 1004 or e.code == 1005), "Wrong exception code")
self.assertTrue(e.code in [1004, 1005], "Wrong exception code")
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function TwitterSearchOrderTest.test_TSO_geo refactored with the following changes:

  • Replace multiple comparisons of same variable with in operator (merge-comparisons)


tso = self.getCopy()
correct_values = [ self.generateInt(minimum=1,maximum=100) for x in range(0,10) ]
correct_values = [self.generateInt(minimum=1,maximum=100) for x in range(10)]
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function TwitterSearchOrderTest.test_TSO_count refactored with the following changes:

  • Replace range(0, x) with range(x) (remove-zero-from-range)


tso = self.getCopy()
correct_values = [ self.generateString() for x in range(0,10) ]
correct_values = [self.generateString() for x in range(10)]
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function TwitterSearchOrderTest.test_TSO_callback refactored with the following changes:

  • Replace range(0, x) with range(x) (remove-zero-from-range)

Comment on lines -420 to +423
value = "foo"
exc_class = NotImplementedError
to = TwitterOrder()
with self.assertRaises(exc_class):
value = "foo"
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function TwitterSearchOrderTest.test_TO_exceptions refactored with the following changes:

  • Move assignments closer to their usage (move-assign)

Comment on lines -34 to -38
data = {
return {
'query': self.movie,
'api-key': self.api_key
}
return data
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function NYTimesReviews._prepare_request_data refactored with the following changes:

  • Inline variable that is immediately returned (inline-immediately-returned-variable)

@sourcery-ai
Copy link
Copy Markdown
Author

sourcery-ai Bot commented Jun 28, 2020

Sourcery Code Quality Report (beta)

✅ Merging this PR will increase code quality in the affected files by 0.01 out of 10.

Before After Change
Quality 8.74 8.75 0.01
Complexity 1.48 1.43 -0.05
Method Length 49.08 48.77 -0.31
Lines 1139 1130 -9
Changed files Quality Before Quality After Quality Change
TwitterSearch/setup.py 9.38 9.46 0.07 ⬆️
TwitterSearch/TwitterSearch/TwitterSearch.py 8.96 8.96 0.0 ⬆️
TwitterSearch/TwitterSearch/TwitterSearchException.py 9.44 9.52 0.08 ⬆️
TwitterSearch/tests/test_ts.py 8.51 8.52 0.01 ⬆️
TwitterSearch/tests/test_tso.py 8.05 8.06 0.01 ⬆️
after/backends/ny_times.py 9.62 9.63 0.01 ⬆️

Here are some functions in these files that still need a tune-up:

File Function Quality Recommendation
TwitterSearch/TwitterSearch/TwitterSearch.py TwitterSearch.send_search 5.44 Split out functionality
TwitterSearch/tests/test_tso.py TwitterSearchOrderTest.test_TSO_geo 5.63 Split out functionality
TwitterSearch/tests/test_ts.py TwitterSearchTest.test_TS_search_tweets 5.83 Split out functionality
TwitterSearch/tests/test_tso.py TwitterSearchOrderTest.test_TSO_filters 5.85 Split out functionality
TwitterSearch/tests/test_tso.py TwitterSearchOrderTest.test_TSO_keywords 6.03 Split out functionality

Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Let us know what you think of it via email or our Gitter!

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