-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored master branch #2
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
print("Renamed {} to {}".format(file, new_file_name)) | ||
print(f"Renamed {file} to {new_file_name}") |
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 call to format with f-string (
use-fstring-for-formatting
)
my_dict = dict() | ||
my_dict = {} | ||
for key, values in ordered_pairs: | ||
if key in my_dict: | ||
raise ValueError("Duplicate key: {}".format(key,)) | ||
raise ValueError(f"Duplicate key: {key}") |
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 dict_raise_on_duplicates
refactored with the following changes:
- Replace dict() with {} (
dict-literal
) - Replace call to format with f-string (
use-fstring-for-formatting
)
sample_list = list() | ||
sample_list = [] | ||
my_list = [random.randint(1, 888898) for num in | ||
range(1, 1000000) if num % 2 == 0] | ||
print('Finished in {} seconds.'.format(timer.duration())) | ||
print(f'Finished in {timer.duration()} seconds.') |
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 31-34
refactored with the following changes:
- Replace list() with [] (
list-literal
) - Replace call to format with f-string (
use-fstring-for-formatting
)
n = 0 | ||
all_times = list() | ||
while n < 10: | ||
all_times = [] | ||
for _ in range(10): | ||
create_new_db() | ||
load_new_perms() | ||
n += 1 |
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 37-42
refactored with the following changes:
- Move assignment closer to its usage within a block (
move-assign-in-block
) - Replace list() with [] (
list-literal
) - Replace while with for (
while-to-for
) - Replace unused for index with underscore (
for-index-underscore
)
print("\nFound {} links".format(len(links))) | ||
print(f"\nFound {len(links)} links") |
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 19-19
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
print("Config file: {}".format(CONFIGFILE)) | ||
print(f"Config file: {CONFIGFILE}") |
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 42-42
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
call(["git", "checkout", str(commit).rstrip()+"~1", file_name]) | ||
call(["git", "checkout", f"{str(commit).rstrip()}~1", file_name]) |
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 7-7
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
for row in reader: | ||
all_addresses.append(row) | ||
all_addresses.extend(iter(reader)) |
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 get_addresses
refactored with the following changes:
- Simplify generator expression (
simplify-generator
) - Replace a for append loop with list extend (
for-append-to-extend
)
counter = 1 | ||
# update header | ||
header_row = all_the_ip_address.pop(0) | ||
header_row.extend(['Country', 'City']) | ||
# get geolocation | ||
for line in all_the_ip_address: | ||
for counter, line in enumerate(all_the_ip_address, start=1): | ||
print("Grabbing geo info for row # {0}".format(counter)) | ||
r = requests.get('https://freegeoip.net/json/{0}'.format(line[0])) | ||
line.extend([str(r.json()['country_name']), str(r.json()['city'])]) | ||
updated_addresses.append(line) | ||
counter += 1 |
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 get_geolocation
refactored with the following changes:
- Move assignment closer to its usage within a block (
move-assign-in-block
) - Replace manual loop counter with call to enumerate (
convert-to-enumerate
)
else: | ||
print('Specify at least 1 argument') | ||
sys.exit() | ||
print('Specify at least 1 argument') | ||
sys.exit() |
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 get_arguments
refactored with the following changes:
- Remove unnecessary else after guard condition (
remove-unnecessary-else
)
Sourcery Code Quality Report✅ Merging this PR will increase code quality in the affected files by 0.85%.
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! |
if r.status_code == 200: | ||
return r.text | ||
else: | ||
return "Sorry, no results found." | ||
return r.text if r.status_code == 200 else "Sorry, no results found." |
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 call_api
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
else: | ||
print('Specify at least 1 argument') | ||
sys.exit() | ||
print('Specify at least 1 argument') | ||
sys.exit() |
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 get_arguments
refactored with the following changes:
- Remove unnecessary else after guard condition (
remove-unnecessary-else
)
html = requests.get('https://plus.googleapis.com/u/0/_/widget/render/comments?first_party_property=YOUTUBE&href=' + url) | ||
html = requests.get( | ||
f'https://plus.googleapis.com/u/0/_/widget/render/comments?first_party_property=YOUTUBE&href={url}' | ||
) | ||
|
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 get_comments
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
else: | ||
for word in comment.split(' '): | ||
if word in negative_words: | ||
negative += 1 | ||
if word in positive_words: | ||
positive += 1 | ||
for word in comment.split(' '): | ||
if word in negative_words: | ||
negative += 1 | ||
if word in positive_words: | ||
positive += 1 |
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 calculate_sentiment
refactored with the following changes:
- Remove unnecessary else after guard condition (
remove-unnecessary-else
)
url = get_arguments() | ||
if url: | ||
if url := get_arguments(): |
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 main
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
)
url = 'https://api.github.com/{0}/{1}/repos?per_page=100&page={2}' | ||
while True: | ||
url = 'https://api.github.com/{0}/{1}/repos?per_page=100&page={2}' | ||
r = requests.get(url.format(group, name, page)) | ||
if r.status_code == 200: | ||
rdata = r.json() | ||
for repo in rdata: | ||
repo_urls.append(repo['clone_url']) | ||
repo_urls.extend(repo['clone_url'] for repo in rdata) |
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 get_total_repos
refactored with the following changes:
- Hoist statements out of for/while loops (
hoist-statement-from-loop
) - Replace a for append loop with list extend (
for-append-to-extend
)
count = 1 | ||
print('Cloning...') | ||
for repo in all_repos: | ||
os.system('Git clone ' + repo) | ||
for count, repo in enumerate(all_repos, start=1): | ||
os.system(f'Git clone {repo}') | ||
print('Completed repo #{0} of {1}'.format(count, len(all_repos))) | ||
count += 1 |
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 clone_repos
refactored with the following changes:
- Move assignment closer to its usage within a block (
move-assign-in-block
) - Replace manual loop counter with call to enumerate (
convert-to-enumerate
) - Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
total = get_total_repos(sys.argv[1], sys.argv[2]) | ||
if total: | ||
if total := get_total_repos(sys.argv[1], sys.argv[2]): |
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 37-38
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
)
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:Help us improve this pull request!