Skip to content

Commit f92a6a7

Browse files
Remove unnecessary elif / else block (HarshCasper#1251)
* Use identity check for comparison to a singleton (HarshCasper#1) Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com> * Refactor unnecessary `else` / `elif` when `if` block has a `continue` statement (HarshCasper#2) Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com> * Refactor unnecessary `else` / `elif` when `if` block has a `return` statement (HarshCasper#3) Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com> Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
1 parent d6613cf commit f92a6a7

File tree

11 files changed

+83
-94
lines changed

11 files changed

+83
-94
lines changed

Python/AWS_Scripts/secretManager.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,4 @@ def getSecretFromSecretManager(self) -> json:
3030
else:
3131
if "SecretString" in getSecretValueResponse:
3232
return json.loads(getSecretValueResponse["SecretString"])
33-
else:
34-
raise ValueError("SecretString not found in reponse")
33+
raise ValueError("SecretString not found in reponse")

Python/Automate_LinkedIN/automate_linkedin.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,7 @@ def automate_linkedin():
100100
send_request = input(input("Enter 1 to continue, 0 to stop "))
101101
if send_request == 1:
102102
continue
103-
else:
104-
return "Sent all requests"
103+
return "Sent all requests"
105104

106105

107106
if __name__ == "__main__":

Python/Cryptocurrency_Converter/crypto_converter.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,9 @@ def validity_of_currencytype(ctype, ftype):
6767
available_cryptocurrencies = ["BTC", "ETH", "ETC", "BCH", "LTC", "ZEC", "ZRX"]
6868
if ctype not in available_cryptocurrencies:
6969
return 1, f"\n{ctype} is not a Cryptocurrency. Try Again!\n"
70-
elif ftype in available_cryptocurrencies:
70+
if ftype in available_cryptocurrencies:
7171
return 1, f"\n{ftype} is not a Fiat Money. Try Again!\n"
72-
else:
73-
return 0, "\nAll Good!"
72+
return 0, "\nAll Good!"
7473

7574

7675
def main():
@@ -88,17 +87,16 @@ def main():
8887
choice = input()
8988
if choice == "y":
9089
continue
91-
elif choice == "n":
92-
return
93-
else:
94-
print("Bad Input Again!")
90+
if choice == "n":
9591
return
92+
print("Bad Input Again!")
93+
return
9694
result = convert_crypto_to_fiat(
9795
crypto_value, crypto_type.upper(), fiat_type.upper()
9896
)
9997
if result is None:
10098
return
101-
elif result == 1:
99+
if result == 1:
102100
continue
103101
print(
104102
f"{crypto_value} {crypto_type.upper()} in {fiat_type.upper()} is --> {result}"
@@ -116,17 +114,16 @@ def main():
116114
choice = input()
117115
if choice == "y":
118116
continue
119-
elif choice == "n":
120-
return
121-
else:
122-
print("Bad Input Again!")
117+
if choice == "n":
123118
return
119+
print("Bad Input Again!")
120+
return
124121
result = convert_fiat_to_crypto(
125122
fiat_value, fiat_type.upper(), crypto_type.upper()
126123
)
127124
if result is None:
128125
return
129-
elif result == 1:
126+
if result == 1:
130127
continue
131128
print(
132129
f"{fiat_value} {fiat_type.upper()} in {crypto_type.upper()} is --> {result}"

Python/Discord_Bot/main.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -260,15 +260,15 @@ async def userinfo(ctx, member: discord.Member = None):
260260

261261
@bot.event
262262
async def on_command_error(ctx, error):
263-
if isinstance(error, commands.NoPrivateMessage):
264-
return await ctx.send("This command dont work in dms channel")
265-
elif isinstance(error, commands.MissingPermissions):
266-
return await ctx.send(
267-
f"It looks like you are missing some permissions\n `{', '.join(error.missing_perms)}`"
268-
)
269-
elif isinstance(error, commands.BotMissingPermissions):
270-
string = error.missing_perms
271-
return await ctx.send(f"Bot Missing Permissions\n`{','.join(string)}`")
263+
if isinstance(error, commands.NoPrivateMessage):
264+
return await ctx.send("This command dont work in dms channel")
265+
if isinstance(error, commands.MissingPermissions):
266+
return await ctx.send(
267+
f"It looks like you are missing some permissions\n `{', '.join(error.missing_perms)}`"
268+
)
269+
if isinstance(error, commands.BotMissingPermissions):
270+
string = error.missing_perms
271+
return await ctx.send(f"Bot Missing Permissions\n`{','.join(string)}`")
272272

273273

274274
bot.run(TOKEN)

Python/Email_Scrape_From_Commits/email_scrape.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ def run_query(token, repo):
1616
)
1717
if res.status_code == 200:
1818
return res.json()
19-
else:
20-
raise Exception(
21-
"Query failed to run by returning code of {}".format(res.status_code)
22-
)
19+
raise Exception(
20+
"Query failed to run by returning code of {}".format(res.status_code)
21+
)
2322

2423

2524
def query_string(name, owner):

Python/Execution_Time/stopwatch.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ def start(self):
2424
if not self.state == "Stopped":
2525
print("Stopwatch is already running.")
2626
return
27-
else:
28-
self.__startTime__ = time.time()
29-
self.state = "Started"
27+
self.__startTime__ = time.time()
28+
self.state = "Started"
3029
return
3130

3231
def lap(self):

Python/PR_Workflow/src/graphqlapi.py

Lines changed: 48 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -13,63 +13,62 @@ def pulls(self):
1313
"""this function returns pull request query"""
1414
if self.tag is not None:
1515
query = """
16-
{ repository(name: "%s", owner: "%s") {
17-
pullRequests(states: %s, last: %i, orderBy: {field: CREATED_AT, direction: ASC},labels:"%s") {
18-
totalCount
19-
nodes {
20-
title
21-
number
22-
comments {
23-
totalCount
24-
}
25-
closedAt
26-
createdAt
27-
labels(last: 10) {
28-
nodes {
29-
name
16+
{ repository(name: "%s", owner: "%s") {
17+
pullRequests(states: %s, last: %i, orderBy: {field: CREATED_AT, direction: ASC},labels:"%s") {
18+
totalCount
19+
nodes {
20+
title
21+
number
22+
comments {
23+
totalCount
24+
}
25+
closedAt
26+
createdAt
27+
labels(last: 10) {
28+
nodes {
29+
name
30+
}
31+
totalCount
32+
}
33+
}
34+
}
3035
}
31-
totalCount
3236
}
33-
}
34-
}
35-
}
36-
}
37-
""" % (
37+
""" % (
3838
self.name,
3939
self.owner,
4040
self.state,
4141
self.countr,
4242
self.tag,
4343
)
4444
return query
45-
else:
46-
query = """
47-
{
48-
repository(name: "%s", owner: "%s") {
49-
pullRequests(states: %s, last: %s, orderBy: {field: CREATED_AT, direction: ASC}) {
50-
totalCount
51-
nodes {
52-
title
53-
number
54-
comments {
55-
totalCount
56-
}
57-
closedAt
58-
createdAt
59-
labels(last: 10) {
60-
nodes {
61-
name
45+
query = """
46+
{
47+
repository(name: "%s", owner: "%s") {
48+
pullRequests(states: %s, last: %s, orderBy: {field: CREATED_AT, direction: ASC}) {
49+
totalCount
50+
nodes {
51+
title
52+
number
53+
comments {
54+
totalCount
55+
}
56+
closedAt
57+
createdAt
58+
labels(last: 10) {
59+
nodes {
60+
name
61+
}
62+
totalCount
63+
}
64+
}
65+
}
6266
}
63-
totalCount
6467
}
65-
}
66-
}
67-
}
68-
}
69-
""" % (
70-
self.name,
71-
self.owner,
72-
self.state,
73-
self.countr,
74-
)
75-
return query
68+
""" % (
69+
self.name,
70+
self.owner,
71+
self.state,
72+
self.countr,
73+
)
74+
return query

Python/PR_Workflow/src/prapi.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ def run_query(query, token):
1010
)
1111
if res.status_code == 200:
1212
return res.json()
13-
else:
14-
raise Exception(
15-
"Query failed to run by returning code of {}. {}".format(
16-
res.status_code, query
17-
)
13+
raise Exception(
14+
"Query failed to run by returning code of {}. {}".format(
15+
res.status_code, query
1816
)
17+
)

Python/PlaystoreScraper/PlaystoreScraper.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,8 @@ def scraper():
136136
ans = input("Press (y) to continue or any other key to exit: ").lower()
137137
if ans == "y":
138138
continue
139-
else:
140-
print("Exiting..")
141-
break
139+
print("Exiting..")
140+
break
142141

143142

144143
if __name__ == "__main__":

Python/Port_Scanner/port_scanner.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ def get_scan_args():
6868
if len(sys.argv) == 2:
6969
print("\nStarting Port: {} Ending Port: {}".format(0, 1024))
7070
return (sys.argv[1], 0, 1024)
71-
elif len(sys.argv) == 3:
71+
if len(sys.argv) == 3:
7272
print("\nStarting Port: {} Ending Port: {}".format(1, sys.argv[2]))
7373
return (sys.argv[1], 0, int(sys.argv[2]))
74-
elif len(sys.argv) == 4:
74+
if len(sys.argv) == 4:
7575
print(
7676
"\nStarting Port: {} Ending Port: {}".format(sys.argv[2], sys.argv[3])
7777
)

Python/Telegram_Bot/markovmeme/text.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ def generate_text(corpus, use_model=True, size=10):
3838

3939
if use_model:
4040
return generate_words_markov(corpus, size=size)
41-
else:
42-
return select_sentence(corpus)
41+
return select_sentence(corpus)
4342

4443

4544
# Word Gram Models

0 commit comments

Comments
 (0)