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

some pylint tidyups #502

Closed
wants to merge 3 commits into from
Closed

some pylint tidyups #502

wants to merge 3 commits into from

Conversation

marksmayo
Copy link

simplification of some conditional statements
fixing of import orders
cleaning up of unneeded chars

marksmayo and others added 2 commits November 15, 2022 23:06
simplification of some conditional statements
fixing of import orders
cleaning up of unneeded chars
@github-actions
Copy link

📝 Docs preview for commit df69924 at: https://6373659b207e6130302a7ad7--typertiangolo.netlify.app

@github-actions
Copy link

📝 Docs preview for commit d702cf2 at: https://639ce9d1a12b8e08e99de3ea--typertiangolo.netlify.app

Copy link
Member

@svlandeg svlandeg left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! Definitely appreciate your contribution.

I left a few spurious comments. I think it will be up to tiangolo to decide whether we want some of these refactorings, or whether we'd keep to the original repo source style.

@@ -62,7 +62,7 @@ class PartialGithubEvent(BaseModel):
"body": f"📝 Docs preview for commit {use_pr.head.sha} at: {settings.input_deploy_url}"
},
)
if not (200 <= response.status_code <= 300):
if not 200 <= response.status_code <= 300:
Copy link
Member

@svlandeg svlandeg Mar 8, 2024

Choose a reason for hiding this comment

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

When there's multiple if statements (implicit here because of the chaining) combined with a negation, I personally find keeping the parentheses more clear & readable - so I would vote to revert this change.

Comment on lines 7 to +10
if username in existing_usernames:
print("The user already exists")
raise typer.Exit()
else:
print(f"User created: {username}")
print(f"User created: {username}")
Copy link
Member

Choose a reason for hiding this comment

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

Throughout the docs, the house style is to use else even if the preceding if raises or returns. While I agree with you that this is not strictly necessary, I do think it contributes to readability to have the else explicitly there. Furthermore, it's more robust in terms of maintenance down the line: if the original if statement ever changes its implementation, the developer won't have to worry about implicit else statements being affected. So overall I think verbosity is prefered in these cases.

Comment on lines 7 to +10
def hello(count, name):
"""Simple program that greets NAME for a total of COUNT times."""
for x in range(count):
click.echo("Hello %s!" % name)
click.echo(f"Hello {name}!")
Copy link
Member

Choose a reason for hiding this comment

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

While F-strings are typically nicer and more readable, there are a few cases where you might prefer not using them. When we're logging things for instance, you might prefer avoiding the str() functionality for cases where the statement wouldn't actually get logged (e.g. if the logging level is higher). That said - I'm not actually sure how click.echo() operates under the hood so I'm not sure whether we want this rewrite in this case or not.

Copy link
Member

Choose a reason for hiding this comment

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

Ah! This one is just that it was an exact copy of Click's tutorial. But they now updated it to use f-strings, so I would take this change. 🤓

Copy link
Member

Choose a reason for hiding this comment

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

cf #891

@svlandeg svlandeg added p5 and removed p3 labels Mar 8, 2024
@svlandeg svlandeg marked this pull request as draft March 11, 2024 14:21
@tiangolo
Copy link
Member

Thanks @marksmayo! 🤓

And thanks @svlandeg for the thorough review! 🙇

For most of the code style changes I would just use what is configured in pre-commit (I'm not a fan of PyLInt, actually).

Soon, after removing support for Python 3.6, I will migrate all to Ruff.

This PR covers too many different things, so it would be better to split it to be able to take some things while not taking others.

Specifically, I would take the changes in the Click examples from "some str {blah}".format(blah=blah) to f-strings. That was just an exact copy of Click's tutorials, but now they updated them, we can update them here as well.

For now, I'll close this one, but feel free to add a new PR changing those Click f-strings! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants