[issue11926] help("keywords") returns incomplete list of keywords
New submission from Carl M. Johnson <cmjohnson.mailinglist@gmail.com>: In Python 3.2, help("keywords") returns the following: Here is a list of the Python keywords. Enter any keyword to get more help. and elif import raise as else in return assert except is try break finally lambda while class for nonlocal with continue from not yield def global or del if pass - - - - This list is missing True, False, and None. ---------- assignee: docs@python components: Documentation messages: 134440 nosy: Carl.M.Johnson, docs@python priority: normal severity: normal status: open title: help("keywords") returns incomplete list of keywords versions: Python 3.2 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue11926> _______________________________________
Changes by Chris Rebert <pybugs@rebertia.com>: ---------- nosy: +cvrebert _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue11926> _______________________________________
Ezio Melotti <ezio.melotti@gmail.com> added the comment: True, False and None are also included in keyword.kwlist:
keyword.kwlist ['False', 'None', 'True', 'and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']
The help() is also missing for 'None' and 'False', but works for 'True':
help('None') no Python documentation found for 'None' help('False') no Python documentation found for 'False' help('True') Help on bool object:
True = class bool(int) | bool(x) -> bool ... On 3.3 it's the same. ---------- nosy: +ezio.melotti stage: -> needs patch versions: +Python 3.3 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue11926> _______________________________________
Sijin Joseph <sijinjoseph@gmail.com> added the comment: Should True, False and None be keywords? Technically True and False are objects of type bool, in fact the only objects of that type allowed. And None is a specially designated object as well. P.S: Can anyone point me to where the help function is defined in the source? ---------- nosy: +sijinjoseph _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue11926> _______________________________________
Sijin Joseph <sijinjoseph@gmail.com> added the comment: @Ezio - help(True), help(False) and help(None) all return the correct documentation for me using latest trunk. I think the quotes around True, False and None might be throwing things off in your case. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue11926> _______________________________________
Ezio Melotti <ezio.melotti@gmail.com> added the comment: This can be fixed by adding 'False', 'None', and 'True' to the Helper.keywords dict in Lib/pydoc.py. I'm not sure what the topic for these should be though. True/False/None are documented in the "built-in constants" section[0] of the doc. An alternative might be to point to 'bool'[1] for True/False or just show the same help of help(True/False/None) (without quotes). [0]: http://docs.python.org/dev/py3k/library/constants.html#built-in-constants [1]: http://docs.python.org/dev/py3k/library/functions.html#bool ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue11926> _______________________________________
Éric Araujo <merwok@netwok.org> added the comment: True and False are keywords in 3.x for the parser (IIUC), even though they’re still instances of bool. ---------- nosy: +eric.araujo _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue11926> _______________________________________
R. David Murray <rdmurray@bitdance.com> added the comment: As part of fixing this we should add a unit test to pydoc that goes something like this: assertEqual(sorted(pydoc.Helper.keywords.keys())), sorted(keyword.kwlist)) ---------- nosy: +r.david.murray _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue11926> _______________________________________
Ezio Melotti <ezio.melotti@gmail.com> added the comment: +1 ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue11926> _______________________________________
Ezio Melotti <ezio.melotti@gmail.com> added the comment: Attached patch adds True/False/None to the list of keywords and a special-cased path to have help('True'/'False'/'None') return the same as help(True/False/None). I also added tests and found out that nonlocal was missing too, so I added it to the list (the changes to Lib/pydoc_data/topics.py are not included in the patch -- use make pydoc-topics in Doc/ to see them). ---------- assignee: docs@python -> ezio.melotti keywords: +needs review, patch stage: needs patch -> patch review versions: +Python 3.1 Added file: http://bugs.python.org/file21816/issue11926.diff _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue11926> _______________________________________
Éric Araujo <merwok@netwok.org> added the comment: I asked about nonlocal in #9724. Patch looks good (I has to repress a gut reaction “eval is evil” :) ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue11926> _______________________________________
Roundup Robot <devnull@devnull> added the comment: New changeset 99d5542399a1 by Ezio Melotti in branch '3.1': #11926: add missing keywords to help("keywords"). http://hg.python.org/cpython/rev/99d5542399a1 New changeset 7b4c853aa07d by Ezio Melotti in branch '3.2': #11926: merge with 3.1. http://hg.python.org/cpython/rev/7b4c853aa07d New changeset 0d8a6833f5be by Ezio Melotti in branch 'default': #11926: merge with 3.2. http://hg.python.org/cpython/rev/0d8a6833f5be New changeset ffd83aeb0b67 by Ezio Melotti in branch '2.7': Backport test from #11926. http://hg.python.org/cpython/rev/ffd83aeb0b67 ---------- nosy: +python-dev _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue11926> _______________________________________
Ezio Melotti <ezio.melotti@gmail.com> added the comment: Fixed True/False/None in 3.1/3.2/3.3, nonlocal in 3.1 (it was already ok in 3.2/3.3), and backported tests on 2.7. Thanks for the pointer to #9724. ---------- resolution: -> fixed stage: patch review -> committed/rejected status: open -> closed _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue11926> _______________________________________
Éric Araujo <merwok@netwok.org> added the comment: Out of curiosity: Any reason you used a containment test with a list instead of a set (IMO more idiomatic, and in 3.2+ also optimized)? I guess it’s to match the rest of the file, but using sets would not change any behavior. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue11926> _______________________________________
Ezio Melotti <ezio.melotti@gmail.com> added the comment: Good question. I considered using sets but then decided to use lists because they don't get rid of duplicates and would make the test fail in the (indeed unlikely) case that a keyword gets added twice (that's actually not possible in Test.keywords because it's a dict, but keyword.kwlist is a list and the implementation of either one could change at some point). In any case it probably doesn't make much difference -- I just preferred to err on the safe side. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue11926> _______________________________________
Éric Araujo <merwok@netwok.org> added the comment: I was too vague. I referred only to “if something in ['True', 'False', 'None']” in pydoc.py ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue11926> _______________________________________
Ezio Melotti <ezio.melotti@gmail.com> added the comment: That's just because I'm used to Python 2 where the {} syntax for sets was not available. I'll try to keep that in mind for the next time. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue11926> _______________________________________
participants (7)
-
Carl M. Johnson
-
Chris Rebert
-
Ezio Melotti
-
R. David Murray
-
Roundup Robot
-
Sijin Joseph
-
Éric Araujo