New GitHub issue #96103 from Gnudini:<br>
<hr>
<pre>
In section [Boolean Operations — and, or, not](https://docs.python.org/3/library/stdtypes.html#boolean-operations-and-or-not) there's Note 3 saying:
> <html>
> <body>
> <!--StartFragment-->
>
> <code class="docutils literal notranslate"><span class="pre">not</span></code> has a lower priority than non-Boolean operators, so …, and <code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">==</span> <span class="pre">not</span> <span class="pre">b</span></code> is a syntax error.
>
> <!--EndFragment-->
> </body>
> </html>
This mistakenly suggests that the reason for `True == not False` constituting a syntax error had to do with operator priority. If that were the case, the expression `2 ** - 1` would yield a syntax error as well, which of course it doesn't. Priority never causes an operator to be drawn in in place of an operand.
The true reason for `True == not False` being a syntax error is that there exists no syntax rule that would produce a [comparison][1] therefrom, since
>comparison ::= or_expr (comp_operator or_expr)*
\- i. e. after the comp_operator `==` an [or_expr][2] must follow, which includes an xor_expr, an and_expr, a [shift_expr][3], an a_expr, an [m_expr][4], a [u_expr][5], a [power][6]…, but no [not_test][7].
By comparison, the priority-wise similar construct `2 ** - 1` in accordance with the power rule
>power ::= (await_expr | primary) ["**" u_expr]
has u_expr following the power operator `**`, thus allowing `- x` on the right hand side.
This wrong impression could be avoided by removing the subclause "_, and `a == not b` is a syntax error_" from the note.
[1]: https://docs.python.org/3/reference/expressions.html#grammar-token-comparison
[2]: https://docs.python.org/3/reference/expressions.html#grammar-token-or-expr
[3]: https://docs.python.org/3/reference/expressions.html#grammar-token-shift-expr
[4]: https://docs.python.org/3/reference/expressions.html#grammar-token-m-expr
[5]: https://docs.python.org/3/reference/expressions.html#grammar-token-u-expr
[6]: https://docs.python.org/3/reference/expressions.html#grammar-token-power
[7]: https://docs.python.org/3/reference/expressions.html#grammar-token-not-test
</pre>
<hr>
<a href="https://github.com/python/cpython/issues/96103">View on GitHub</a>
<p>Labels: docs</p>
<p>Assignee: </p>