This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: help("keywords") returns incomplete list of keywords
Type: Stage: resolved
Components: Documentation Versions: Python 3.1, Python 3.2, Python 3.3
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: ezio.melotti Nosy List: Carl.M.Johnson, cvrebert, docs@python, eric.araujo, ezio.melotti, python-dev, r.david.murray, sijinjoseph
Priority: normal Keywords: needs review, patch

Created on 2011-04-26 01:55 by Carl.M.Johnson, last changed 2022-04-11 14:57 by admin. This issue is now closed.

File name Uploaded Description Edit
issue11926.diff ezio.melotti, 2011-04-28 02:20 Patch against 3.1 to add True/False/None and nonlocal. review
Messages (16)
msg134440 - (view) Author: Carl M. Johnson (Carl.M.Johnson) Date: 2011-04-26 01:55
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.
msg134441 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2011-04-26 02:03
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.
msg134456 - (view) Author: Sijin Joseph (sijinjoseph) Date: 2011-04-26 12:46
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?
msg134457 - (view) Author: Sijin Joseph (sijinjoseph) Date: 2011-04-26 12:50
@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.
msg134522 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2011-04-27 02:17
This can be fixed by adding 'False', 'None', and 'True' to the Helper.keywords dict in Lib/  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).

msg134548 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-04-27 10:23
True and False are keywords in 3.x for the parser (IIUC), even though they’re still instances of bool.
msg134575 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2011-04-27 15:06
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))
msg134621 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2011-04-27 21:42
msg134635 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2011-04-28 02:20
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/ are not included in the patch -- use make pydoc-topics in Doc/ to see them).
msg134641 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-04-28 04:02
I asked about nonlocal in #9724.

Patch looks good (I has to repress a gut reaction “eval is evil” :)
msg134644 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-04-28 04:59
New changeset 99d5542399a1 by Ezio Melotti in branch '3.1':
#11926: add missing keywords to help("keywords").

New changeset 7b4c853aa07d by Ezio Melotti in branch '3.2':
#11926: merge with 3.1.

New changeset 0d8a6833f5be by Ezio Melotti in branch 'default':
#11926: merge with 3.2.

New changeset ffd83aeb0b67 by Ezio Melotti in branch '2.7':
Backport test from #11926.
msg134645 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2011-04-28 05:06
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.
msg134671 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-04-28 12:36
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.
msg134672 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2011-04-28 12:44
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.
msg134673 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-04-28 12:52
I was too vague.  I referred only to “if something in ['True', 'False', 'None']” in
msg134722 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2011-04-28 21:51
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.
Date User Action Args
2022-04-11 14:57:16adminsetgithub: 56135
2011-04-28 21:51:04ezio.melottisetmessages: + msg134722
2011-04-28 12:52:45eric.araujosetmessages: + msg134673
2011-04-28 12:44:19ezio.melottisetmessages: + msg134672
2011-04-28 12:36:49eric.araujosetmessages: + msg134671
2011-04-28 05:06:21ezio.melottisetstatus: open -> closed
resolution: fixed
messages: + msg134645

stage: patch review -> resolved
2011-04-28 04:59:48python-devsetnosy: + python-dev
messages: + msg134644
2011-04-28 04:02:26eric.araujosetmessages: + msg134641
2011-04-28 02:20:30ezio.melottisetfiles: + issue11926.diff
versions: + Python 3.1
messages: + msg134635

assignee: docs@python -> ezio.melotti
keywords: + patch, needs review
stage: needs patch -> patch review
2011-04-27 21:42:45ezio.melottisetmessages: + msg134621
2011-04-27 15:06:23r.david.murraysetnosy: + r.david.murray
messages: + msg134575
2011-04-27 10:23:41eric.araujosetnosy: + eric.araujo
messages: + msg134548
2011-04-27 02:17:04ezio.melottisetmessages: + msg134522
2011-04-26 12:50:22sijinjosephsetmessages: + msg134457
2011-04-26 12:46:32sijinjosephsetnosy: + sijinjoseph
messages: + msg134456
2011-04-26 02:03:54ezio.melottisetversions: + Python 3.3
nosy: + ezio.melotti

messages: + msg134441

stage: needs patch
2011-04-26 02:00:26cvrebertsetnosy: + cvrebert
2011-04-26 01:55:59Carl.M.Johnsoncreate