-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored main branch #11
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: main
Are you sure you want to change the base?
Conversation
if bool(os.getenv("PRODUCTION")): | ||
db = client.Main | ||
else: | ||
db = client.Test | ||
return db | ||
return client.Main if bool(os.getenv("PRODUCTION")) else client.Test |
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 setup_db
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
) - Replace if statement with if expression (
assign-if-exp
)
if url := os.getenv("REDIS_URL"): | ||
k = {} | ||
if password := os.getenv("REDIS_PASS"): | ||
k["password"] = password | ||
redis: Redis = Redis.from_url(url, **k) | ||
else: | ||
redis: Redis = Redis() | ||
return redis | ||
if not (url := os.getenv("REDIS_URL")): | ||
return Redis() | ||
k = {} | ||
if password := os.getenv("REDIS_PASS"): | ||
k["password"] = password | ||
return Redis.from_url(url, **k) |
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 setup_redis
refactored with the following changes:
- Lift return into if (
lift-return-into-if
) - Swap if/else branches (
swap-if-else-branches
) - Remove unnecessary else after guard condition (
remove-unnecessary-else
)
settings = Settings.from_data(req.json()) | ||
|
||
return settings | ||
return Settings.from_data(req.json()) |
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 setup_settings
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
raise CommandFailed("Item `{}` not found!".format(item)) | ||
raise CommandFailed(f"Item `{item}` not found!") | ||
|
||
item_name = redis.get("dank:item:{}:name".format(actual_item[0])) | ||
item_name = redis.get(f"dank:item:{actual_item[0]}: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.
Function DankMemer.dankitem
refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting
)
plugins/fun.py
Outdated
return "\N{KEYCAP TEN}" if c == 10 else str(c) + "\u20e3" | ||
return "\N{KEYCAP TEN}" if c == 10 else f'{c}⃣' |
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 to_keycap
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
) - Remove unnecessary calls to
str()
from formatted values in f-strings (remove-str-from-fstring
)
url, headers={"Authorization": self.bot.amari_auth} | ||
) as req: | ||
if req.status_code == 200: | ||
data = req.json()["data"] | ||
else: | ||
data = [] | ||
|
||
url, headers={"Authorization": self.bot.amari_auth} | ||
) as req: | ||
data = req.json()["data"] if req.status_code == 200 else [] |
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 Amari.fetch_guild_data
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
return "Mee6 Level: " + str(data[0]) | ||
return f"Mee6 Level: {str(data[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.
Function Mee6.display
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
return ( | ||
"Required Role" + s(data) + ": " + format_list([f"<@&{i}>" for i in data]) | ||
) | ||
return (f"Required Role{s(data)}: " + format_list([f"<@&{i}>" for i in data])) |
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 Role.display
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
raise ArgumentParsingError("Invalid role ID ({})".format(role_str)) | ||
raise ArgumentParsingError(f"Invalid role ID ({role_str})") |
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 Role.convert
refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting
)
squid/flask_support.py
Outdated
"Response must be an InteractionResponse object but recieved {}: ({})".format( | ||
type(response), response.__repr__() | ||
) | ||
f"Response must be an InteractionResponse object but recieved {type(response)}: ({response.__repr__()})" | ||
) | ||
|
||
|
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 flask_compat.wrapper
refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting
)
r = {} | ||
for v, k in self.settings.get(ctx.command.cog.db_name, {}).items(): | ||
r[v] = data.get(ctx.command.cog.db_name, {}).get(v, k.default) | ||
return r | ||
return { | ||
v: data.get(ctx.command.cog.db_name, {}).get(v, k.default) | ||
for v, k in self.settings.get(ctx.command.cog.db_name, {}).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.
Function Settings.guild_settings
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
) - Convert for loop into dictionary comprehension (
dict-comprehension
)
if len(l) == 0: | ||
if not l: | ||
return "" | ||
elif len(l) == 1: | ||
return str(l[0]) | ||
elif len(l) == 2: | ||
return "{} and {}".format(l[0], l[1]) | ||
return f"{l[0]} and {l[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 format_list
refactored with the following changes:
- Simplify sequence length comparison (
simplify-len-comparison
) - Replace call to format with f-string. (
use-fstring-for-formatting
)
value = seconds // count | ||
if value: | ||
if value := seconds // count: |
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 display_time
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
)
), "Could not parse any time information from '{}'. Examples of valid strings: '8h', '2d8h5m20s', '2m4s'".format( | ||
time_str | ||
) | ||
), f"Could not parse any time information from '{time_str}'. Examples of valid strings: '8h', '2d8h5m20s', '2m4s'" | ||
|
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 parse_time
refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting
)
description="Unknown interaction: {}".format(ctx.interaction.data.name), | ||
description=f"Unknown interaction: {ctx.interaction.data.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.
Function SquidBot.unknown_command
refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting
)
squid/bot/command.py
Outdated
parent = self.full_parent_name | ||
if parent: | ||
return parent + " " + self.name | ||
if parent := self.full_parent_name: | ||
return f'{parent} {self.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.
Function SquidCommand.qualified_name
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
) - Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
if self._user["member"]: | ||
return self._user["member"] | ||
return self._user["user"] | ||
return self._user["member"] or self._user["user"] |
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 SquidContext.author
refactored with the following changes:
- Simplify if expression by using or (
or-if-exp-identity
) - Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
)
if remaining == "0" and response.status_code != 429: | ||
pass | ||
# we've depleted our current bucket | ||
# delta = utils._parse_ratelimit_header(response, use_clock=self.use_clock) | ||
# # _log.debug('A rate limit bucket has been exhausted (bucket: %s, retry: %s).', bucket, delta) | ||
# maybe_lock.defer() | ||
# self.loop.call_later(delta, lock.release) | ||
|
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 HttpClient.request
refactored with the following changes:
- Remove redundant conditional (
remove-redundant-if
)
This removes the following comments ( why? ):
# maybe_lock.defer()
# we've depleted our current bucket
# This is handling exceptions from the request
# delta = utils._parse_ratelimit_header(response, use_clock=self.use_clock)
# self.loop.call_later(delta, lock.release)
# # _log.debug('A rate limit bucket has been exhausted (bucket: %s, retry: %s).', bucket, delta)
if isinstance(o, InteractionResponseType): | ||
return None | ||
return o.__dict__ | ||
return None if isinstance(o, InteractionResponseType) else o.__dict__ |
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 InteractionResponse.default
refactored with the following changes:
- Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
)
squid/models/member.py
Outdated
return (self.name if len(self.name) <= 32 else self.name[:32] + "...").replace( | ||
"@", "@\u200b" | ||
) | ||
return ( | ||
self.name if len(self.name) <= 32 else f'{self.name[:32]}...' | ||
).replace("@", "@\u200b") |
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 Member.safe_name
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
Sourcery Code Quality Report❌ Merging this PR will decrease code quality in the affected files by 0.04%.
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
main
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
main
branch, then run:Help us improve this pull request!