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

PEP 8: Add note regarding exception message string literals #2606

Conversation

erlend-aasland
Copy link
Contributor

@erlend-aasland erlend-aasland commented May 13, 2022

Resolves #2604

pep-0008.txt Outdated Show resolved Hide resolved
Copy link
Member

@AA-Turner AA-Turner left a comment

Location in the text seems fine to me.

A

pep-0008.txt Outdated

Strive to keep exception message string literals on one line,
in order to make them easily greppable.
If your exception message exceeds the maximum line length,
Copy link
Member

@AA-Turner AA-Turner May 13, 2022

Choose a reason for hiding this comment

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

This could be a link, but equally it follows the line length section directly

Edit: non-commital suggestion as I wasn't very clear on what I meant:

Suggested change
If your exception message exceeds the maximum line length,
If your exception message exceeds the `maximum line length`_,

Copy link
Contributor Author

@erlend-aasland erlend-aasland May 13, 2022

Choose a reason for hiding this comment

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

I'm not sure it's needed, but I'm also fine with a link. I'll leave it for you and Christopher to decide 🙂

(IIRC, both of you have the commit bit here, so feel free to apply the suggestion when you've decided.)

Copy link
Member

@CAM-Gerlach CAM-Gerlach May 14, 2022

Choose a reason for hiding this comment

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

I'm not sure it's needed, but I'm also fine with a link.

I'm not sure it is either, since it is a short section and immediately above. But I don't have a strong opinion.

I'll leave it for you and Christopher to decide slightly_smiling_face

You mean @Rosuav ? Or are you referring to me (CAM)?

Copy link
Contributor Author

@erlend-aasland erlend-aasland May 14, 2022

Choose a reason for hiding this comment

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

I was referring to you, CAM :) (Actually, I was unaware that there was more than two PEP editors)

Copy link
Member

@AA-Turner AA-Turner May 14, 2022

Choose a reason for hiding this comment

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

I was unaware that there was more than two PEP editors

Guido, Barry, Brett, ChrisA, Jelle, Adam, Cam, and Hugo are the current complement -- a few more than two!

A

Copy link
Contributor

@Rosuav Rosuav May 14, 2022

Choose a reason for hiding this comment

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

It's okay, most of us are invisible :) For what it's worth, I have no opinion on the specific wording, but I fully approve of the sentiment here.

Copy link
Contributor Author

@erlend-aasland erlend-aasland May 16, 2022

Choose a reason for hiding this comment

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

Can I mark this as resolved? Did you decide about the link?

Copy link
Member

@CAM-Gerlach CAM-Gerlach left a comment

LGTM, thanks @erlend-aasland

pep-0008.txt Outdated Show resolved Hide resolved
pep-0008.txt Outdated

Strive to keep exception message string literals on one line,
in order to make them easily greppable.
If your exception message exceeds the maximum line length,
Copy link
Member

@CAM-Gerlach CAM-Gerlach May 14, 2022

Choose a reason for hiding this comment

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

I'm not sure it's needed, but I'm also fine with a link.

I'm not sure it is either, since it is a short section and immediately above. But I don't have a strong opinion.

I'll leave it for you and Christopher to decide slightly_smiling_face

You mean @Rosuav ? Or are you referring to me (CAM)?

@gvanrossum
Copy link
Member

@gvanrossum gvanrossum commented May 14, 2022

@warsaw What do you think? It’s a bit of a u-turn but I think grepping for errors would be more effective.

Copy link
Member

@gvanrossum gvanrossum left a comment

Definitely wait for Barry to review.

I wonder if we should generalize to "error message"?

@erlend-aasland
Copy link
Contributor Author

@erlend-aasland erlend-aasland commented May 14, 2022

Definitely wait for Barry to review.

Sure. I should've done the same for PEP 7; sorry 'bout the rushed merge.

I wonder if we should generalize to "error message"?

+1

@warsaw
Copy link
Member

@warsaw warsaw commented May 14, 2022

What do you think? It’s a bit of a u-turn but I think grepping for errors would be more effective.

Agreed

I wonder if we should generalize to "error message"?

+1

I guess I'm +0 on this change for PEP 8. We have to be careful not to overload PEP 8 for every possible corner case, but I agree with @gvanrossum on greppability.

Let me quibble just a bit with the wording.

pep-0008.txt Outdated
@@ -241,6 +241,17 @@ Another such case is with ``assert`` statements.

Make sure to indent the continued line appropriately.


Error Message String Literals
Copy link
Member

@warsaw warsaw May 14, 2022

Choose a reason for hiding this comment

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

I think just saying "Error messages" would be sufficient. I have to pause to think about what "Error message string literals" are. Exception strings? Something else? Is there something special about string literals for errors?

Copy link
Member

@CAM-Gerlach CAM-Gerlach May 14, 2022

Choose a reason for hiding this comment

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

My one concern with that is that readers might think its talking about the wording/formatting of error messages themself, rather than concerned with how string literals for error messages are formatted in the code. But I can see both sides of this.

Copy link
Contributor Author

@erlend-aasland erlend-aasland May 14, 2022

Choose a reason for hiding this comment

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

How about just dropping "Literals"?

"Strive to keep error message strings on one line"

vs.

"Strive to keep error messages on one line"

Copy link
Contributor Author

@erlend-aasland erlend-aasland May 16, 2022

Choose a reason for hiding this comment

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

PTAL; I've removed "literals".

pep-0008.txt Outdated
Error Message String Literals
-----------------------------

Strive to keep error message string literals on one line,
Copy link
Member

@warsaw warsaw May 14, 2022

Choose a reason for hiding this comment

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

s/error message string literals/error messages/

Strive to keep error message string literals on one line,
in order to make them easily greppable.
If your error message exceeds the maximum line length,
try to mitigate it by reducing indent, or just bend that rule.
Copy link
Member

@warsaw warsaw May 14, 2022

Choose a reason for hiding this comment

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

Maybe we don't need the "or just bend that rule." and the invocation of practicality over purity? All of that should be well understood if you read PEP 8.

Copy link
Member

@CAM-Gerlach CAM-Gerlach May 14, 2022

Choose a reason for hiding this comment

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

I suppose the benefit of making it explicit is that it establishes that preserving greppability should generally take priority over following the line length restriction, which is otherwise left ambigious by the current wording and thus would seem to neuter much of the intent of the addition here, perhaps.

Copy link
Contributor Author

@erlend-aasland erlend-aasland May 16, 2022

Choose a reason for hiding this comment

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

I prefer the explicity of "or just bend that rule", but I will remove it if there is a strong opposition to it.

Copy link
Member

@warsaw warsaw left a comment

Wording suggestions.

@erlend-aasland
Copy link
Contributor Author

@erlend-aasland erlend-aasland commented May 14, 2022

I wonder if we should generalize to "error message"?

FWIW, I'm inclined to not applying this generalisation to the PEP 7 change (#2605).

@warsaw
Copy link
Member

@warsaw warsaw commented May 16, 2022

I've thought about this over the weekend. @gvanrossum I don't know, I kind of think maybe this and the PEP 7 changes shouldn't go in. It's seems vague and less focused on making code readable than the effects of that code. PEP 8 is already huge, so I think the bar has to be pretty high on the "this helps readability" scale.

@erlend-aasland
Copy link
Contributor Author

@erlend-aasland erlend-aasland commented May 16, 2022

I've thought about this over the weekend. @gvanrossum I don't know, I kind of think maybe this and the PEP 7 changes shouldn't go in. It's seems vague and less focused on making code readable than the effects of that code. PEP 8 is already huge, so I think the bar has to be pretty high on the "this helps readability" scale.

Ok. Again, sorry for not waiting on your review. I'll be more careful next time.

I'll prepare a PR for reverting this.

@gvanrossum
Copy link
Member

@gvanrossum gvanrossum commented May 16, 2022

In the face of Barry's strong opinion I back out on updating the PEPs. I still think we should generally not be breaking up error messages across lines.

@gvanrossum gvanrossum closed this May 16, 2022
@erlend-aasland
Copy link
Contributor Author

@erlend-aasland erlend-aasland commented May 16, 2022

I still think we should generally not be breaking up error messages across lines.

Ditto

@erlend-aasland erlend-aasland deleted the pep8/greppable-exception-messages branch May 16, 2022
erlend-aasland added a commit to erlend-aasland/peps that referenced this issue May 16, 2022
)"

Based on post-merge feedback, it was decided to revert this change.

See the original PR (pythonGH-2605), the proposed PR for PEP 8 (pythonGH-2606), and
the issue (pythonGH-2604) for the discussions.

This reverts commit c787739.
erlend-aasland added a commit that referenced this issue May 17, 2022
…2608)

Based on post-merge feedback, it was decided to revert this change.

See the original PR (GH-2605), the proposed PR for PEP 8 (GH-2606), and
the issue (GH-2604) for the discussions.

This reverts commit c787739.
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.

6 participants