[issue16438] Numeric operator predecence confusing
New submission from Yongzhi Pan: http://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-compl... "All numeric types (except complex) support the following operations, sorted by ascending priority." It list '-' after '+', '/' after '*'. That is to mean '-' has higher precedence than '+'. That is wrong, and is contradicting with here: http://docs.python.org/3/reference/expressions.html#summary This should be made clear. ---------- assignee: docs@python components: Documentation messages: 175163 nosy: docs@python, fossilet priority: normal severity: normal status: open title: Numeric operator predecence confusing versions: Python 2.7, Python 3.2, Python 3.3, Python 3.4 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue16438> _______________________________________
Jesús Cea Avión added the comment: Precedence ordered per row. Same row, same precedence. I don't see any problem. It is natural math precedence. Closed as invalid. ---------- nosy: +jcea resolution: -> invalid _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue16438> _______________________________________
Changes by Mark Dickinson <dickinsm@gmail.com>: ---------- status: open -> closed _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue16438> _______________________________________
Yongzhi Pan added the comment: I mean the text at the first link need fix. '+' and '-' are not on the same row. And the doc says: "sorted by ascending priority", that means they have ascending priority. The table in the reference is just right. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue16438> _______________________________________
Jesús Cea Avión added the comment: You are right, Yongzhi Pan. Reopening. Not sure how to solve it. Delegating to docs@python. ---------- resolution: invalid -> status: closed -> open _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue16438> _______________________________________
Changes by Meador Inge <meadori@gmail.com>: ---------- nosy: +meador.inge _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue16438> _______________________________________
Changes by Ezio Melotti <ezio.melotti@gmail.com>: ---------- keywords: +easy nosy: +ezio.melotti stage: -> needs patch type: -> enhancement _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue16438> _______________________________________
Kiet Tran added the comment: I was trying to fix this, but I ran into a couple questions. 1) Once I put, say, "x + y" and "x - y" into the same table cell, what would a good format be? My preferred format is to have them on separate lines in the cell, but after a lot of googling on the syntax of reST (and trials and errors), I'm still unable to figure out how to do it. Using bullet points would mean I have to align elements in the "Notes" column with the ones in the "Operation" column somehow. Alternatively, I can separate them by comma, but the table would look a bit cluttered. 2) Should the functions abs, int, etc., belong in the same table that's meant to list operators by precedence? ---------- nosy: +ktt3ja _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue16438> _______________________________________
Yongzhi Pan added the comment: One possible solution: We do not list priorities of the operations, instead link to the precedence table in the language reference. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue16438> _______________________________________
Kiet Tran added the comment: Good idea. ---------- keywords: +patch Added file: http://bugs.python.org/file28075/16438.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue16438> _______________________________________
Ezio Melotti added the comment:
I'm still unable to figure out how to do it
You could look at Doc/library/unittest.rst, there are some tables that span multiple lines. If you want a newline in the output too I think you have to add a blank line in the cell. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue16438> _______________________________________
Kiet Tran added the comment: That document actually doesn't have any table that spans multiple lines. Here's the html page: http://docs.python.org/dev/library/unittest.html Actually, I already know how to make a table span multiple lines from this stackoverflow page: http://stackoverflow.com/questions/13504595/multi-line-table-cell-in-restruc... However, the problem is having the items in different columns match, as it depends on the width of the table, which is not fixed. For example, notice how the table is formatted nicely here: http://imgur.com/y1hLg But if I shrink the width, the formatting just goes wrong: http://imgur.com/Oct9m This is particularly problematic because some elements in the table have long lines. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue16438> _______________________________________
Mark Lawrence added the comment: I find the numeric operator predecence simply wrong, not confusing, so +1 from me for applying the attached patch from ktt3ja. It's as simple as possible but no simpler :) ---------- nosy: +BreamoreBoy versions: +Python 3.5 -Python 3.2, Python 3.3 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue16438> _______________________________________
ron <ron@mailinator.com> added the comment: Any progress on this? ---------- nosy: +ronron _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue16438> _______________________________________
Change by Mark Lawrence <breamoreboy@gmail.com>: ---------- nosy: -BreamoreBoy _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue16438> _______________________________________
Elliot Edmunds <edmundselliot@gmail.com> added the comment: I agree that linking to the precedence table is probably the best solution. A different option would be to add an extra column listing the "priority" and rank the priorities of the different operations. ---------- nosy: +Elliot Edmunds _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue16438> _______________________________________
Change by Anjali Malik <anjaliimalik@outlook.com>: ---------- pull_requests: +9781 stage: needs patch -> patch review _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue16438> _______________________________________
Mariatta Wijaya <mariatta@python.org> added the comment: I'm actually thinking perhaps the "see :ref:`operator-summary`" clause should be separate and under Notes below the table, as opposed to current PR: ``` All numeric types (except complex) support the following operations (for priorities of the operations, see :ref:`operator-summary`) ``` reads oddly to me. ---------- nosy: +Mariatta _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue16438> _______________________________________
Julien Palard <julien+python@palard.fr> added the comment: New changeset 4576b5431bd597df7581fe3c852b315e47e4b230 by Julien Palard (Anjali) in branch 'master': bpo-16438: Doc: confusing text regarding numeric precedence corrected (GH-10521) https://github.com/python/cpython/commit/4576b5431bd597df7581fe3c852b315e47e... ---------- nosy: +mdk _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue16438> _______________________________________
Change by miss-islington <mariatta.wijaya+miss-islington@gmail.com>: ---------- pull_requests: +15545 pull_request: https://github.com/python/cpython/pull/15904 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue16438> _______________________________________
Change by miss-islington <mariatta.wijaya+miss-islington@gmail.com>: ---------- pull_requests: +15546 pull_request: https://github.com/python/cpython/pull/15905 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue16438> _______________________________________
miss-islington <mariatta.wijaya+miss-islington@gmail.com> added the comment: New changeset 80db4b4be54ccdb5b67821506b6db2b27bd7c28a by Miss Islington (bot) in branch '3.8': bpo-16438: Doc: confusing text regarding numeric precedence corrected (GH-10521) https://github.com/python/cpython/commit/80db4b4be54ccdb5b67821506b6db2b27bd... ---------- nosy: +miss-islington _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue16438> _______________________________________
miss-islington <mariatta.wijaya+miss-islington@gmail.com> added the comment: New changeset 9210b5826fab5248ac28a15c1b8b39ae949d0ef8 by Miss Islington (bot) in branch '3.7': bpo-16438: Doc: confusing text regarding numeric precedence corrected (GH-10521) https://github.com/python/cpython/commit/9210b5826fab5248ac28a15c1b8b39ae949... ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue16438> _______________________________________
Change by Julien Palard <julien+python@palard.fr>: ---------- resolution: -> fixed stage: patch review -> resolved status: open -> closed _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue16438> _______________________________________
participants (13)
-
Anjali Malik -
Elliot Edmunds -
Ezio Melotti -
Jesús Cea Avión -
Julien Palard -
Kiet Tran -
Mariatta Wijaya -
Mark Dickinson -
Mark Lawrence -
Meador Inge -
miss-islington -
ron -
Yongzhi Pan