-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
Sample code for the article on for loops #620
base: master
Are you sure you want to change the base?
Conversation
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.
LGTM, two file name typos and a question about whitespaces around the self-documenting expression in f-strings.
|
||
numbers = [1, 2, 3, 4, 5, 6] | ||
for number in numbers: | ||
print(f"{number = }") |
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.
flake8 compains and I was also wondering about it, I've generally only seen this used without whitespace:
print(f"{number = }") | |
print(f"{number=}") |
pycodestyle
, which implements the check, seems to be stubborn about keeping it this way: PyCQA/pycodestyle#1201
$ flake8 break_continue.py
break_continue.py:11:20: E251 unexpected spaces around keyword / parameter equals
break_continue.py:11:22: E202 whitespace before '}'
break_continue.py:11:22: E251 unexpected spaces around keyword / parameter equals
But I know you're using space around the equals sign also in the f-string tutorial.
So IDK, I guess the linters don't fail on it?
If you decide to change it, you'd also have to change it in the written tutorial.
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.
If I remember correctly, in one of my previous articles I used this feature without spaces and I guess it was Geir Arne who suggested adding the spaces for readability. However, I don't think this is a written rule.
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.
Ok, yeah I'm fine with leaving it considering it passes our linter checks. @gahjelle should we note this somewhere, that we'll ignore E251 and E202 for these cases?
python-for-loop/upacking.py
Outdated
points = [(1, 4), (3, 6), (7, 3)] | ||
|
||
for x, y in points: | ||
print(f"{x = } and {y = }") |
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.
Same as in the previous comment, flake8 doesn't like the whitespace:
print(f"{x = } and {y = }") | |
print(f"{x=} and {y=}") |
Where to put new files:
my-awesome-article
How to merge your changes: