Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2dd6c9d

Browse files
authored
PEP 7: Allow breaking lines before operators ("Knuth's style") (GH-3931)
As discussed in: https://discuss.python.org/t/62402 It doesn't make much sense for C and Python to be different here, and the reasons for "Knuth's style" in PEP 8 apply to C code as well.
1 parent 337a97e commit 2dd6c9d

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

peps/pep-0007.rst

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,20 +140,24 @@ Code lay-out
140140
"cannot create '%.100s' instances",
141141
type->tp_name);
142142
143-
* When you break a long expression at a binary operator, the
144-
operator goes at the end of the previous line, and braces should be
145-
formatted as shown. E.g.:
143+
* When you break a long expression at a binary operator, braces
144+
should be formatted as shown:
146145

147146
.. code-block::
148147
:class: good
149148
150-
if (type->tp_dictoffset != 0 && base->tp_dictoffset == 0 &&
151-
type->tp_dictoffset == b_size &&
152-
(size_t)t_size == b_size + sizeof(PyObject *))
149+
if (type->tp_dictoffset != 0
150+
&& base->tp_dictoffset == 0
151+
&& type->tp_dictoffset == b_size
152+
&& (size_t)t_size == b_size + sizeof(PyObject *))
153153
{
154154
return 0; /* "Forgive" adding a __dict__ only */
155155
}
156156
157+
It's OK to put operators at ends of lines, especially to be
158+
consistent with surrounding code.
159+
(See :ref:`PEP 8 <pep8-operator-linebreak>` for a longer discussion.)
160+
157161
* Vertically align line continuation characters in multi-line macros.
158162

159163
* Macros intended to be used as a statement should use the

peps/pep-0008.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,9 @@ Another such case is with ``assert`` statements.
257257

258258
Make sure to indent the continued line appropriately.
259259

260+
261+
.. _`pep8-operator-linebreak`:
262+
260263
Should a Line Break Before or After a Binary Operator?
261264
------------------------------------------------------
262265

0 commit comments

Comments
 (0)