Skip to content
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

[Discussion] Unify code style #67

Closed
wants to merge 4 commits into from
Closed

Conversation

jchristgit
Copy link
Member

@jchristgit jchristgit commented May 2, 2018

So, I've went ahead and ran all Python files through black. My motivation behind this is that black enforces a consistent style throughout the project, and with a community project, I think that that's useful.

I'd be very interested for opinions towards this. The only thing I dislike is the wrapping to multiple lines of lines with long comments - but it's easy to fix this by simply putting the comment above, and it's not too common either. Looking forward to your input.

One more thing, it's also possible to use black in CI with black --check which returns a status code depending on whether or not something would've been changed, useful for not having to check style on PRs ourselves.

Copy link
Member

@lemonsaurus lemonsaurus left a comment

Choose a reason for hiding this comment

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

Most of these changes are clear improvements, in my opinion. It changes a bunch of ''s into "'s, which is great, and it unifies multiline stuff to a certain degree. however, I think it's a bit inconsistent about it.

I've left comments in the many places that made me go wtf, most of them are keyword args in an Embed constructor and occasionally just odd stuff that needs to be fixed by a human.

I think this PR might be worth doing, if we get some more reviews and make all the changes that need making - but considering on how many points I found myself disagreeing with this, I would not be in favor of adding this to CI, I think.

bot/cogs/bot.py Outdated
@@ -153,27 +169,37 @@ def codeblock_stripping(self, msg: str):
# This check is to avoid all nodes being parsed as expressions.
# (e.g. words over multiple lines)
if not all(isinstance(node, ast.Expr) for node in tree.body):
codeblock_tag = await self.bot.get_cog("Tags").get_tag_data("codeblock")
codeblock_tag = await self.bot.get_cog("Tags").get_tag_data(
Copy link
Member

Choose a reason for hiding this comment

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

this one strikes me as weird. not really a readability improvement.

"Authorization": CLICKUP_KEY,
"Content-Type": "application/json"
}
HEADERS = {"Authorization": CLICKUP_KEY, "Content-Type": "application/json"}
Copy link
Member

Choose a reason for hiding this comment

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

also not sure how this is an improvement. seems inconsistent with the other changes.

else:
# Save all the lists with their IDs so that we can get at them later
for project in result["projects"]:
for list_ in project["lists"]:
self.lists[list_["name"]] = list_["id"]
self.lists[f"{project['name']}/{list_['name']}"] = list_["id"] # Just in case we have duplicates
self.lists[f"{project['name']}/{list_['name']}"] = list_[
Copy link
Member

Choose a reason for hiding this comment

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

this is also crazy

embed = Embed(
colour=Colour.red(),
description=f"`{result['ECODE']}`: {result['err']}"
colour=Colour.red(), description=f"`{result['ECODE']}`: {result['err']}"
Copy link
Member

Choose a reason for hiding this comment

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

?? this seems inconsistent with other changes.


for member in result["team"]["members"]:
embed.add_field(
name=member["user"]["username"],
value=member["user"]["id"]
name=member["user"]["username"], value=member["user"]["id"]
Copy link
Member

Choose a reason for hiding this comment

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

and again. maybe I just don't get it.

"res": 300,
"color": 808080
}
data = {"latex": parsed, "res": 300, "color": 808080}
Copy link
Member

Choose a reason for hiding this comment

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

I also liked this better multilined.

bot/cogs/math.py Outdated

async with self.bot.http_session.post(LATEX_URL, data=data) as resp:
html = await resp.text()

name = search(r'hist\.request\.basename = "(?P<url>[^"]+)"', html).group('url')
name = search(r'hist\.request\.basename = "(?P<url>[^"]+)"', html).group(
Copy link
Member

Choose a reason for hiding this comment

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

the fuck

bot/formatter.py Outdated

# strip the command off bot. and ()
stripped_command = self.command.name.replace(HELP_PREFIX, "").replace("()", "")
stripped_command = self.command.name.replace(HELP_PREFIX, "").replace(
Copy link
Member

Choose a reason for hiding this comment

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

this is also super weird.

@@ -74,7 +73,10 @@ def add_line(self, line='', *, empty=False):
The line was too big for the current :attr:`max_size`.
"""
if len(line) > self.max_size - len(self.prefix) - 2:
raise RuntimeError('Line exceeds maximum page size %s' % (self.max_size - len(self.prefix) - 2))
raise RuntimeError(
"Line exceeds maximum page size %s"
Copy link
Member

Choose a reason for hiding this comment

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

why are we using c-style % interpolation?

@@ -129,26 +141,31 @@ def event_check(reaction_: Reaction, user_: Member):

no_restrictions = (
# Pagination is not restricted
not restrict_to_user or
not restrict_to_user
or
# The reaction was by a whitelisted user
Copy link
Member

Choose a reason for hiding this comment

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

naw, this part doesn't work for me. it'd be better to have an inline comment, I think. or something else. just find any other solution. we can't have that lonely or

Copy link
Member

@lemonsaurus lemonsaurus left a comment

Choose a reason for hiding this comment

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

there's.. a lot of things that I don't agree with. I made it about 3/4ths before I gave up. I just don't think this is good enough currently, it would take a whole lot of changes to make it acceptable to merge.

DEVTEST_CHANNEL, HELP1_CHANNEL, HELP2_CHANNEL,
HELP3_CHANNEL, HELP4_CHANNEL, MODERATOR_ROLE, OWNER_ROLE,
PYTHON_CHANNEL, PYTHON_GUILD, VERIFIED_ROLE
ADMIN_ROLE,
Copy link
Member

Choose a reason for hiding this comment

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

this is still kinda insane.

url="https://github.com/discord-python/bot",
icon_url=BOT_AVATAR_URL
)
embed.set_author(name="Python Bot", url="https://github.com/discord-python/bot", icon_url=BOT_AVATAR_URL)
Copy link
Member

Choose a reason for hiding this comment

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

I still prefer the old one here. whenever we list things like this, it's nice to multiline it.

)
embed = Embed(colour=Colour.red(), description=f"`{result['ECODE']}`: {result['err']}")
Copy link
Member

Choose a reason for hiding this comment

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

not an improvement

name=member["user"]["username"],
value=member["user"]["id"]
)
embed.add_field(name=member["user"]["username"], value=member["user"]["id"])
Copy link
Member

Choose a reason for hiding this comment

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

prefer the old one.

name=f"{project['name']} ({project['id']})",
value=lists
)
embed.add_field(name=f"{project['name']} ({project['id']})", value=lists)
Copy link
Member

Choose a reason for hiding this comment

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

I like this multilined.

f"Error encountered when trying to unhiphopify {member.display_name}:\n"
f"{response}"
)
log.warning(f"Error encountered when trying to unhiphopify {member.display_name}:\n" f"{response}")
Copy link
Member

Choose a reason for hiding this comment

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

I prefer the way this used to be.

env={}, # Disable environment variables for security
stdout=PIPE,
stderr=STDOUT,
) # reroute all to stdout
Copy link
Member

Choose a reason for hiding this comment

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

comment in wrong place.

for _ in range(timeout*4): # Check if done every .25 seconds for `timeout` seconds
await asyncio.sleep(1/4)
proc = Popen(
[ # noqa: B603,S603
Copy link
Member

Choose a reason for hiding this comment

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

this probably breaks flake8, noqa is on the wrong line.

ADMIN_ROLE, BOT_COMMANDS_CHANNEL, DEVTEST_CHANNEL,
HELPERS_CHANNEL, MODERATOR_ROLE, OWNER_ROLE,
SITE_API_KEY, SITE_API_TAGS_URL, TAG_COOLDOWN
ADMIN_ROLE,
Copy link
Member

Choose a reason for hiding this comment

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

gdude doesn't love this

BOT_COMMANDS_CHANNEL,
HELPERS_CHANNEL
)
TEST_CHANNELS = (DEVTEST_CHANNEL, BOT_COMMANDS_CHANNEL, HELPERS_CHANNEL)
Copy link
Member

Choose a reason for hiding this comment

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

whyyyy

@jchristgit
Copy link
Member Author

I agree that some of the changes are fairly weird, and having an automated program mess with things like bot/constants.py or long imports with from x import (y, z, a, b, c) is kinda bound for terror. Regarding multi lining, it probably only operates based on line length, sometimes resulting in weird things like

my_long_function_call('does').some_stuff(
    True
)

which just looks weird. I also agree with the comments being super weird sometimes. I'll close it for now, maybe we can find a better way to get a more consistent code style throughout the project at some point.

@jchristgit jchristgit closed this May 5, 2018
@lemonsaurus
Copy link
Member

the idea of unifying code style is a great one. and I wouldn't mind if we enforced it strictly - but if we're going to do that, we need to absolutely 100% agree on what that code style should be. if we could find a tool sort of like Black but which allowed us to customize it to our liking ... but I doubt such a tool exists.

@jchristgit jchristgit deleted the unified-code-formatting branch May 5, 2018 08:44
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.

None yet

3 participants