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) *  |
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) *  |
Date: 2011-04-27 02:17 |
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 |
|
|
msg134548 - (view) |
Author: Éric Araujo (eric.araujo) *  |
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) *  |
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) *  |
Date: 2011-04-27 21:42 |
+1 |
|
|
msg134635 - (view) |
Author: Ezio Melotti (ezio.melotti) *  |
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/topics.py are not included in the patch -- use make pydoc-topics in Doc/ to see them). |
|
|
msg134641 - (view) |
Author: Éric Araujo (eric.araujo) *  |
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)  |
Date: 2011-04-28 04:59 |
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 |
|
|
msg134645 - (view) |
Author: Ezio Melotti (ezio.melotti) *  |
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) *  |
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) *  |
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) *  |
Date: 2011-04-28 12:52 |
I was too vague. I referred only to “if something in ['True', 'False', 'None']” in pydoc.py |
|
|
msg134722 - (view) |
Author: Ezio Melotti (ezio.melotti) *  |
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. |
|
|