[issue22106] Python 2 docs 'control flow/pass' section contains bad example
New submission from Charles Newey: URL: https://docs.python.org/2/tutorial/controlflow.html#pass-statements Quoted verbatim: The pass statement does nothing. It can be used when a statement is required syntactically but the program requires no action. For example: while True: ... pass # Busy-wait for keyboard interrupt (Ctrl+C) ... While the example illustrates the point, it *may* give bad ideas to novice programmers reading it - while True: pass is an antipattern as it's very inefficient. -- assignee: docs@python components: Documentation messages: 224296 nosy: Charles.Newey, docs@python priority: normal severity: normal status: open title: Python 2 docs 'control flow/pass' section contains bad example type: enhancement versions: Python 2.7 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22106 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22106] Python 2 docs 'control flow/pass' section contains bad example
Ezio Melotti added the comment: Do you have any suggestion? The section already includes examples about empty classes and as placeholder inside functions, and the only other realistic situations I can think of is inside an except to ignore errors -- but that might be considered an anti-pattern too. It could be used with for loops if you want to e.g. consume an iterator, or with the with statement if you want to create an empty file, but these cases are not very common. -- nosy: +ezio.melotti ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22106 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22106] Python 2 docs 'control flow/pass' section contains bad example
Charles Newey added the comment: Your point about using pass with the with statement sounds like a better example than using pass in a loop. Perhaps even something like adding a note to the example to clarify it: # Don't use this in Python code - it is for illustrative purposes only while True: pass # Busy-wait for keyboard interrupt (Ctrl+C) On the other hand -- one could argue that the documentation should not show incorrect uses of Python syntax at all. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22106 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22106] Python 2 docs 'control flow/pass' section contains bad example
R. David Murray added the comment: How about something like: for x in my_generator(): pass # Exhaust co-routine generator to make sure all data is processed. I have no idea if you'd ever actually do that in a well-structured co-routine context, though, not having written very much of that kind of code. -- nosy: +r.david.murray ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22106 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22106] Python 2 docs 'control flow/pass' section contains bad example
Charles Newey added the comment: @David I have no idea either (no having written much of that sort of code myself either), but that looks more sensible. I'm just nitpicking really, anyway. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22106 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22106] Python 2 docs 'control flow/pass' section contains bad example
Ezio Melotti added the comment: Keep in mind that this is in one of the first sections of the tutorial, where try/except, with, and generators have not been introduced yet. Maybe the comment could be changed to a simpler loop forever (use ctrl+c to stop) so that it doesn't suggest that this is the way to wait for keyboard interrupts and/or a note like note that this will use 100% of the CPU could be added as well. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22106 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22106] Python 2 docs 'control flow/pass' section contains bad example
Raymond Hettinger added the comment: Sorry Charles, this is a non-issue. The section does a great job communicating what pass does. It has been in the docs since 2007 and no harm has come of it. -- nosy: +rhettinger resolution: - not a bug status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22106 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22106] Python 2 docs 'control flow/pass' section contains bad example
Changes by Ezio Melotti ezio.melo...@gmail.com: -- stage: - resolved ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22106 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com