Skip to content

Braces example for multiline conditionals#284

Merged
warsaw merged 2 commits into
python:masterfrom
warsaw:issue283
Jun 10, 2017
Merged

Braces example for multiline conditionals#284
warsaw merged 2 commits into
python:masterfrom
warsaw:issue283

Conversation

@warsaw

@warsaw warsaw commented Jun 3, 2017

Copy link
Copy Markdown
Member

Closes #283

Comment thread pep-0007.txt

* 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
Copy Markdown
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
Copy Markdown
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.

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

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.

Comment thread pep-0007.txt Outdated
* 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
Copy Markdown
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
Copy Markdown
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