-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored master 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: master
Are you sure you want to change the base?
Conversation
| process = psutil.Process(os.getpid()) | ||
| mem = process.get_memory_info()[0] / float(2 ** 20) | ||
| return mem | ||
| return process.get_memory_info()[0] / float(2 ** 20) |
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 memory_usage_psutil refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| mem = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / rusage_denom | ||
| return mem | ||
| rusage_denom *= rusage_denom | ||
| return resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / rusage_denom |
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 memory_usage_resource refactored with the following changes:
- Replace assignment with augmented assignment (
aug-assign) - Inline variable that is immediately returned (
inline-immediately-returned-variable)
| @@ -1,4 +1,5 @@ | |||
| ''' Super simple module to create basic random data for tutorials''' | |||
|
|
|||
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.
Lines 14-14 refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore)
| csv_file = open('cms_scrape.csv', 'w') | ||
| with open('cms_scrape.csv', 'w') as csv_file: | ||
| csv_writer = csv.writer(csv_file) | ||
| csv_writer.writerow(['headline', 'summary', 'video_link']) | ||
|
|
||
| csv_writer = csv.writer(csv_file) | ||
| csv_writer.writerow(['headline', 'summary', 'video_link']) | ||
| for article in soup.find_all('article'): | ||
| headline = article.h2.a.text | ||
| print(headline) | ||
|
|
||
| for article in soup.find_all('article'): | ||
| headline = article.h2.a.text | ||
| print(headline) | ||
| summary = article.find('div', class_='entry-content').p.text | ||
| print(summary) | ||
|
|
||
| summary = article.find('div', class_='entry-content').p.text | ||
| print(summary) | ||
| try: | ||
| vid_src = article.find('iframe', class_='youtube-player')['src'] | ||
|
|
||
| try: | ||
| vid_src = article.find('iframe', class_='youtube-player')['src'] | ||
| vid_id = vid_src.split('/')[4] | ||
| vid_id = vid_id.split('?')[0] | ||
|
|
||
| vid_id = vid_src.split('/')[4] | ||
| vid_id = vid_id.split('?')[0] | ||
| yt_link = f'https://youtube.com/watch?v={vid_id}' | ||
| except Exception as e: | ||
| yt_link = None | ||
|
|
||
| yt_link = f'https://youtube.com/watch?v={vid_id}' | ||
| except Exception as e: | ||
| yt_link = None | ||
| print(yt_link) | ||
|
|
||
| print(yt_link) | ||
| print() | ||
|
|
||
| print() | ||
|
|
||
| csv_writer.writerow([headline, summary, yt_link]) | ||
|
|
||
| csv_file.close() | ||
| csv_writer.writerow([headline, summary, yt_link]) |
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.
Lines 9-37 refactored with the following changes:
- Use
withwhen opening file to ensure closure (ensure-file-closed)
| messages.success(request, f'Your account has been created! You are now able to log in') | ||
| messages.success( | ||
| request, | ||
| 'Your account has been created! You are now able to log in', | ||
| ) | ||
|
|
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 register refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring)
| messages.success(request, f'Your account has been updated!') | ||
| messages.success(request, 'Your account has been updated!') |
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 profile refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring)
| if self.request.user == post.author: | ||
| return True | ||
| return False | ||
| return self.request.user == post.author |
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 PostUpdateView.test_func refactored with the following changes:
- Simplify conditional into return statement (
return-identity)
| if self.request.user == post.author: | ||
| return True | ||
| return False | ||
| return self.request.user == post.author |
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 PostDeleteView.test_func refactored with the following changes:
- Simplify conditional into return statement (
return-identity)
| messages.success(request, f'Your account has been created! You are now able to log in') | ||
| messages.success( | ||
| request, | ||
| 'Your account has been created! You are now able to log in', | ||
| ) | ||
|
|
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 register refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring)
| messages.success(request, f'Your account has been updated!') | ||
| messages.success(request, 'Your account has been updated!') |
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 profile refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring)
| if self.request.user == post.author: | ||
| return True | ||
| return False | ||
| return self.request.user == post.author |
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 PostUpdateView.test_func refactored with the following changes:
- Simplify conditional into return statement (
return-identity)
| if self.request.user == post.author: | ||
| return True | ||
| return False | ||
| return self.request.user == post.author |
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 PostDeleteView.test_func refactored with the following changes:
- Simplify conditional into return statement (
return-identity)
| messages.success(request, f'Your account has been created! You are now able to log in') | ||
| messages.success( | ||
| request, | ||
| 'Your account has been created! You are now able to log in', | ||
| ) | ||
|
|
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 register refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring)
| messages.success(request, f'Your account has been updated!') | ||
| messages.success(request, 'Your account has been updated!') |
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 profile refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring)
| if self.request.user == post.author: | ||
| return True | ||
| return False | ||
| return self.request.user == post.author |
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 PostUpdateView.test_func refactored with the following changes:
- Simplify conditional into return statement (
return-identity)
| mem = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / rusage_denom | ||
| return mem | ||
| rusage_denom *= rusage_denom | ||
| return resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / rusage_denom |
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 memory_usage_resource refactored with the following changes:
- Replace assignment with augmented assignment (
aug-assign) - Inline variable that is immediately returned (
inline-immediately-returned-variable)
| if day.weekday() == 5 or day.weekday() == 6: | ||
| return False | ||
| return True | ||
| return day.weekday() not in [5, 6] |
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 Employee.is_workday refactored with the following changes:
- Simplify conditional into return statement (
return-identity) - Replace multiple comparisons of same variable with
inoperator (merge-comparisons)
| self.employees = [] | ||
| else: | ||
| self.employees = employees | ||
| self.employees = [] if employees is None else employees |
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 Manager.__init__ refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| def sentence(sentence): | ||
| for word in sentence.split(): | ||
| yield word | ||
| yield from sentence.split() |
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 sentence refactored with the following changes:
- Replace yield inside for loop with yield from (
yield-from)
| total_1 = total_1 + random.randint(-6, 8) | ||
| total_2 = total_2 + random.randint(-5, 6) | ||
| total_1 += random.randint(-6, 8) | ||
| total_2 += random.randint(-5, 6) |
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.
Lines 32-33 refactored with the following changes:
- Replace assignment with augmented assignment (
aug-assign)
| for item in pl_response['items']: | ||
| vid_ids.append(item['contentDetails']['videoId']) | ||
|
|
||
| vid_ids = [item['contentDetails']['videoId'] for item in pl_response['items']] |
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.
Lines 28-31 refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension)
| for item in pl_response['items']: | ||
| vid_ids.append(item['contentDetails']['videoId']) | ||
|
|
||
| vid_ids = [item['contentDetails']['videoId'] for item in pl_response['items']] |
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.
Lines 23-26 refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension)
| if balance < 0: | ||
| balance = 0 | ||
|
|
||
| balance = max(balance, 0) |
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.
Lines 21-23 refactored with the following changes:
- Replace comparison with min/max call (
min-max-identity)
| # print(json.dumps(data, indent=2)) | ||
|
|
||
| usd_rates = dict() | ||
| usd_rates = {} |
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.
Lines 11-11 refactored with the following changes:
- Replace dict() with {} (
dict-literal)
| @@ -1,4 +1,5 @@ | |||
| ''' Super simple module to create basic random data for tutorials''' | |||
|
|
|||
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.
Lines 14-14 refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore)
| def __init__(self, first, last, pay, employees=None): | ||
| super().__init__(first, last, pay) | ||
| self.employees = employees if employees else [] | ||
| self.employees = employees or [] |
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 Manager.__init__ refactored with the following changes:
- Simplify if expression by using or (
or-if-exp-identity)
Sourcery Code Quality Report✅ Merging this PR will increase code quality in the affected files by 0.38%.
Here are some functions in these files that still need a tune-up:
Legend and ExplanationThe emojis denote the absolute quality of the code:
The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request. 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! Help us improve this quality report! |
Branch
masterrefactored 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
masterbranch, then run:Help us improve this pull request!