Skip to content

Comments

audit#2

Open
DiabeticTurtle wants to merge 411 commits intodevelopmentfrom
main
Open

audit#2
DiabeticTurtle wants to merge 411 commits intodevelopmentfrom
main

Conversation

@DiabeticTurtle
Copy link
Owner

No description provided.

Copy link
Contributor

@code-review-doctor code-review-doctor bot left a comment

Choose a reason for hiding this comment

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

Looks good. Worth considering though. View full project report here.


info_json = Path(__file__).parent.resolve() / "info.json"
with open(info_json, encoding="utf-8") as f:
__plugin_info__ = json.loads(f.read())
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
__plugin_info__ = json.loads(f.read())
__plugin_info__ = json.load(f)

This can be simplified by using json.load(...). More details.

if args["nick"]:
matched_here = []
for user in matched:
if any([user.nick and piece.lower() in user.nick.lower() for piece in args["nick"]]):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if any([user.nick and piece.lower() in user.nick.lower() for piece in args["nick"]]):
if any(user.nick and piece.lower() in user.nick.lower() for piece in args["nick"]):

any can take a generator, so constructing a list first may be unnecessary. Read more.

if args["name"]:
matched_here = []
for user in matched:
if any([piece.lower() in user.display_name.lower() for piece in args["name"]]):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if any([piece.lower() in user.display_name.lower() for piece in args["name"]]):
if any(piece.lower() in user.display_name.lower() for piece in args["name"]):

As above, Constructing a list first may be unnecessary.

if args["not-nick"]:
matched_here = []
for user in matched:
if not any([user.nick and piece.lower() in user.nick.lower() for piece in args["not-nick"]]):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if not any([user.nick and piece.lower() in user.nick.lower() for piece in args["not-nick"]]):
if not any(user.nick and piece.lower() in user.nick.lower() for piece in args["not-nick"]):

As above, Constructing a list first may be unnecessary.

if args["not-user"]:
matched_here = []
for user in matched:
if not any([piece.lower() in user.name.lower() for piece in args["not-user"]]):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if not any([piece.lower() in user.name.lower() for piece in args["not-user"]]):
if not any(piece.lower() in user.name.lower() for piece in args["not-user"]):

Again, Constructing a list first may be unnecessary.

if args["not-discrim"]:
matched_here = []
for user in matched:
if not any([disc == int(user.discriminator) for disc in args["not-discrim"]]):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if not any([disc == int(user.discriminator) for disc in args["not-discrim"]]):
if not any(disc == int(user.discriminator) for disc in args["not-discrim"]):

Same as above: Constructing a list first may be unnecessary.


info_json = Path(__file__).parent.resolve() / "info.json"
with open(info_json, encoding="utf-8") as f:
__plugin_info__ = json.loads(f.read())
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
__plugin_info__ = json.loads(f.read())
__plugin_info__ = json.load(f)

This can be simplified by using json.load(...). Explained here.


info_json = Path(__file__).parent.resolve() / "info.json"
with open(info_json, encoding="utf-8") as f:
__plugin_info__ = json.loads(f.read())
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
__plugin_info__ = json.loads(f.read())
__plugin_info__ = json.load(f)

This can be simplified by using json.load(...). More details.

try:
user = await self.bot.get_or_fetch_user(user_id)
except (discord.NotFound, Exception):
raise commands.BadArgument('"{}" not found. Invalid user ID.'.format(user_id))
Copy link
Contributor

Choose a reason for hiding this comment

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

f-string is easier to read, write, and less computationally expensive than legacy string formatting. More details.

except Exception as exc:
err = f"{type(exc).__name__}: {str(exc)}"
raise commands.BadArgument(
"Error renaming {name}#{discrim}.\n```Haskell\n{error}\n```".format(
Copy link
Contributor

Choose a reason for hiding this comment

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

As above, Consider using f-string instead.

Copy link
Contributor

@code-review-doctor code-review-doctor bot left a comment

Choose a reason for hiding this comment

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

Worth considering. View full project report here.

from discord.ext import commands


class SafeFormat(object):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
class SafeFormat(object):
class SafeFormat:

SafeFormat inherits from object by default, so explicitly inheriting from object is redundant. Removing it keeps the code simpler. Read more.

self.__dict = kw

def __getitem__(self, name):
return self.__dict.get(name, SafeString('{%s}' % name))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return self.__dict.get(name, SafeString('{%s}' % name))
return self.__dict.get(name, SafeString(f'{{{name}}}'))

f-string is easier to read, write, and less computationally expensive than legacy string formatting. More.

try:
super().__getattr__(name)
except AttributeError:
return SafeString('%s.%s}' % (self[:-1], name))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return SafeString('%s.%s}' % (self[:-1], name))
return SafeString(f'{self[:-1]}.{name}}}')

As above, Consider using f-string instead.

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.

2 participants