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

Braces example for multiline conditionals #284

Merged
merged 2 commits into from
Jun 10, 2017
Merged

Conversation

warsaw
Copy link
Member

@warsaw warsaw commented Jun 3, 2017

Closes #283

@@ -124,11 +124,13 @@ Code lay-out
type->tp_name);

* When you break a long expression at a binary operator, the
operator goes at the end of the previous line, e.g.::
operator goes at the end of the previous line, and braces should be
Copy link
Member

Choose a reason for hiding this comment

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

Actually I think the brace should be moved only if the indentation of continuation lines matches the indentation of the following code. In the following case the brace should be kept at the end of the line:

        if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
                             "invalid escape sequence '\\%c'",
                             *first_invalid_escape) < 0) {
            Py_DECREF(result);
            return NULL;
        }

Copy link
Member Author

Choose a reason for hiding this comment

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

That actually looks a bit weird to me, though I can understand the rationale. I'd personally prefer a rule that states the open brace not to be hanging in all multiline conditional cases.

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

My heuristic is { on the if line, but on on a newline if the if takes at least 2 lines.

pep-0007.txt Outdated
@@ -124,11 +124,13 @@ Code lay-out
type->tp_name);

* When you break a long expression at a binary operator, the
operator goes at the end of the previous line, e.g.::
operator goes at the end of the previous line, and braces should be
formatted as show. E.g.::
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be 'as shown'?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep!

@warsaw warsaw merged commit 3800904 into python:master Jun 10, 2017
@warsaw warsaw deleted the issue283 branch June 10, 2017 03:46
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.

5 participants