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.
This commit is contained in:
parent
337a97e9ab
commit
2dd6c9dfee
|
@ -140,20 +140,24 @@ Code lay-out
|
||||||
"cannot create '%.100s' instances",
|
"cannot create '%.100s' instances",
|
||||||
type->tp_name);
|
type->tp_name);
|
||||||
|
|
||||||
* When you break a long expression at a binary operator, the
|
* When you break a long expression at a binary operator, braces
|
||||||
operator goes at the end of the previous line, and braces should be
|
should be formatted as shown:
|
||||||
formatted as shown. E.g.:
|
|
||||||
|
|
||||||
.. code-block::
|
.. code-block::
|
||||||
:class: good
|
:class: good
|
||||||
|
|
||||||
if (type->tp_dictoffset != 0 && base->tp_dictoffset == 0 &&
|
if (type->tp_dictoffset != 0
|
||||||
type->tp_dictoffset == b_size &&
|
&& base->tp_dictoffset == 0
|
||||||
(size_t)t_size == b_size + sizeof(PyObject *))
|
&& type->tp_dictoffset == b_size
|
||||||
|
&& (size_t)t_size == b_size + sizeof(PyObject *))
|
||||||
{
|
{
|
||||||
return 0; /* "Forgive" adding a __dict__ only */
|
return 0; /* "Forgive" adding a __dict__ only */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
It's OK to put operators at ends of lines, especially to be
|
||||||
|
consistent with surrounding code.
|
||||||
|
(See :ref:`PEP 8 <pep8-operator-linebreak>` for a longer discussion.)
|
||||||
|
|
||||||
* Vertically align line continuation characters in multi-line macros.
|
* Vertically align line continuation characters in multi-line macros.
|
||||||
|
|
||||||
* Macros intended to be used as a statement should use the
|
* Macros intended to be used as a statement should use the
|
||||||
|
|
|
@ -257,6 +257,9 @@ Another such case is with ``assert`` statements.
|
||||||
|
|
||||||
Make sure to indent the continued line appropriately.
|
Make sure to indent the continued line appropriately.
|
||||||
|
|
||||||
|
|
||||||
|
.. _`pep8-operator-linebreak`:
|
||||||
|
|
||||||
Should a Line Break Before or After a Binary Operator?
|
Should a Line Break Before or After a Binary Operator?
|
||||||
------------------------------------------------------
|
------------------------------------------------------
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue