classification
Title: Improve help('non-topic') response
Type: enhancement Stage: resolved
Components: Documentation, Library (Lib) Versions: Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: BreamoreBoy, Jessica.McKellar, docs@python, elias, ezio.melotti, jesstess, python-dev, serhiy.storchaka, terry.reedy, zach.ware
Priority: normal Keywords: patch

Created on 2013-12-14 01:34 by terry.reedy, last changed 2015-02-28 22:46 by serhiy.storchaka. This issue is now closed.

Files
File name Uploaded Description Edit
help-response.patch elias, 2013-12-21 20:38 Improve help('non-topic') response review
empty-help-response.patch elias, 2014-03-04 04:52 Issue 19980: Show error message when help('') is run from interactive prompt. review
issue19980.patch BreamoreBoy, 2014-06-03 15:00 review
Issue19980.diff BreamoreBoy, 2014-07-28 18:43 Change following review review
issue19880v3.diff BreamoreBoy, 2014-12-30 14:24 Fixed line endings problem.
issue19880v4.diff serhiy.storchaka, 2015-02-28 19:25 review
Messages (26)
msg206157 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2013-12-14 01:34
>>> help(1)
# help on int
>>> help(b'a')
# help on bytes
>>> help('a')
no Python documentation found for 'a'

The reason for this unhelpful response is that strings are treated differently from all other non-class objects. (msg205861 thought this a bug.) The strings value is matched against strings that would be recognized at the help> prompt given after help().

>>> help('topics')
# list of TOPICS
>>> help('LISTS')
# information about mutable sequences

Suggestion: add something more about what to do. Example enhanced response:

No Python documentation found for 'a'. Try help('help') for information on recognized strings or help(str) for help on the str class.

I believe this could be backported since help() is intented for interactive use only.
msg206159 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2013-12-14 01:47
IMHO this must be changed.

>>> help('')
# nothing!!!
>>> help('a')
Help on module a:

...

I happened to have a module called a.py in the default directory.
msg206777 - (view) Author: Elias Zamaria (elias) * Date: 2013-12-21 20:38
I have created a patch that fixes this issue that terry.reedy described. It does not fix the problem described BreamoreBoy involving the empty string.

Please note that this is my first patch for Python so let me know if I am missing something or if I can do anything else to help.
msg212690 - (view) Author: Elias Zamaria (elias) * Date: 2014-03-04 04:52
Here is a patch that addresses the empty string problem described by @BreamoreBoy. I am not sure if this is the best way to handle it but it is better than what we have now.
msg216084 - (view) Author: Jessica McKellar (Jessica.McKellar) Date: 2014-04-14 14:43
Elias, thanks for your patch!

I think it's important to add the second part of Terry's suggestion which gives the user a specific next step to take, namely:

> Try help('help') for information on recognized strings or help(str) for help on the str class.

Can you add that to your patch?

Additionally, we'll want to make sure we don't accidentally break this new functionality. Can you add a few test cases, for example what happens when you run help on a module (e.g. help("os"), 2) help on an instance of a class (e.g. help(1)), and help on a string that doesn't have a special meaning, (e.g. help("abcxyz"))?

I don't see any existing tests for help(), but it is an instance of site._Helper (as reported by type(help)), and site tests live in Lib/test/test_site.py. It also gets loaded into builtins, so tests could also live in Lib/test/test_builtins.py.
msg216142 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2014-04-14 18:03
help() uses lib/pydoc.py and pydoc tests are in test/test_pydoc.py
I think tests for things help does that pydoc does not do (help on topics?) should be in site.py.
msg217668 - (view) Author: Elias Zamaria (elias) * Date: 2014-05-01 00:25
Sorry for the late response but I have been busy with various things. I may
be able to work on this but I don't know when or how long it will take me.
I would suggest that someone else work on it if anyone wants it done any
time soon. I am sorry about this.

On Mon, Apr 14, 2014 at 7:43 AM, Jessica McKellar <report@bugs.python.org>wrote:

>
> Jessica McKellar added the comment:
>
> Elias, thanks for your patch!
>
> I think it's important to add the second part of Terry's suggestion which
> gives the user a specific next step to take, namely:
>
> > Try help('help') for information on recognized strings or help(str) for
> help on the str class.
>
> Can you add that to your patch?
>
> Additionally, we'll want to make sure we don't accidentally break this new
> functionality. Can you add a few test cases, for example what happens when
> you run help on a module (e.g. help("os"), 2) help on an instance of a
> class (e.g. help(1)), and help on a string that doesn't have a special
> meaning, (e.g. help("abcxyz"))?
>
> I don't see any existing tests for help(), but it is an instance of
> site._Helper (as reported by type(help)), and site tests live in
> Lib/test/test_site.py. It also gets loaded into builtins, so tests could
> also live in Lib/test/test_builtins.py.
>
> ----------
> nosy: +Jessica.McKellar, jesstess
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <http://bugs.python.org/issue19980>
> _______________________________________
>
msg218721 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-05-17 22:52
I propose the following.  help('') returns help on strings in the same way that help([]) and help({}) returns help on lists and dicts respectively, further help(''.method) returns help on the string method or an attribute error, so this appears to me consistent.  help('doh') returns enhanced output along the lines Terry suggested in msg206157.  help('module') gives the path to the module as well as the help output, if any, as I think this could be useful in cases where you're looking for problems and have a stdlib module masked by a file of your own.  Thoughts?

If we can come to an agreement I'll try and work up a patch.

Note that I've tried looking at the test code and it didn't make much sense to me, pointers welcome.

I've also just signed the contributor's agreement.
msg219154 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-05-26 14:20
Anybody?
msg219166 - (view) Author: Jessica McKellar (jesstess) * Date: 2014-05-26 17:45
@BreamoreBoy, thanks for following up on this!


> I propose the following.  help('') returns help on strings in the same way that help([]) and help({}) returns help on lists and dicts respectively,

Sounds good.

> further help(''.method) returns help on the string method or an attribute error, so this appears to me consistent.

This already happens (which I think you are saying, but it's a bit confusing in reading your message which functionality you are proposing to add and which functionality you are restating that already exists).

> help('doh') returns enhanced output along the lines Terry suggested in msg206157.

Sounds good.

> help('module') gives the path to the module as well as the help output, if any, as I think this could be useful in cases where you're looking for problems and have a stdlib module masked by a file of your own.

I think you are stating the current functionality?

> Note that I've tried looking at the test code and it didn't make much sense to me, pointers welcome.

Do you have specific questions?

Terry suggests that help() tests for functionality using pydoc live in test_pydoc.py, and that help() tests for functionality not using pydoc live in test_site.py.
msg219695 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-06-03 15:00
Please find attached a first pass at a patch file.  Help('') produces help for the str class as discussed.  I found the difference between help('help') and help() very confusing.  The former produced the help output but left you at the interactive prompt, the latter took you to the help utility.  Both now take you to the help utility.  I've changed the test file but two test fail, here's the output from one as they're virtually identical.

FAIL: test_input_strip (test.test_pydoc.PydocDocTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "c:\cpython\lib\test\test_pydoc.py", line 429, in test_input_strip
    self.assertEqual(expected, result)
AssertionError: 'No P[49 chars]e\'.\nUse help("help") or just help() to get t[66 chars]ass.' != 'No P[49 chars]e\'.\r\nUse help("help") or just help() to get[70 chars]ass.'
- No Python documentation found for 'test.i_am_not_here'.
+ No Python documentation found for 'test.i_am_not_here'.
?                                                        +
- Use help("help") or just help() to get the interactive help utility.
+ Use help("help") or just help() to get the interactive help utility.
?                                                                     +
  Use help(str) for help on the str class.

I can't see where the difference between the .\nUse and .\r\nUse is coming from so thought fresh eyes would do the job.
msg221098 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-06-20 15:23
Can somebody set the stage to patch review and give my patch the once over please, thanks.
msg223847 - (view) Author: Zachary Ware (zach.ware) * (Python committer) Date: 2014-07-24 15:11
Mark, would you like to update your patch to address my review comments?
msg224177 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-07-28 18:43
I suppose that technically this can only go into 3.5, but is there any real reason that this couldn't be backported?
msg230029 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-10-26 16:01
ping.
msg231506 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-11-22 00:21
Anybody?
msg231507 - (view) Author: Zachary Ware (zach.ware) * (Python committer) Date: 2014-11-22 02:22
Mark, did you test your latest patch?
msg231514 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-11-22 08:05
Did I test the last patch?  I would hope so but I simply can't remember as it's nearly four months ago, sorry :(
msg231519 - (view) Author: Zachary Ware (zach.ware) * (Python committer) Date: 2014-11-22 13:57
In that case, it would be good to make sure it still applies and passes the
tests. Last time I tried it didn't, and I was called away before I could
leave a note to that effect (for which I am sorry).  However, I don't have
a strong enough opinion on this issue for me to have fixed your patch or
even to have kept it in mind to come back to later.
msg233206 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-12-30 14:24
I screwed up, sorry folks.  If the latest patch isn't correct I give up as it's three strikes and I'm out :(
msg234910 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2015-01-28 19:56
Ping.
msg236896 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2015-02-28 16:45
Pang :(
msg236903 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-02-28 19:22
There is a problem with the patch. When you are in interactive help utility, then the request 'help' runs nested interactive help utility. The difference between unpatched behavior is that now you need press Ctrl-D or 'q' twice to exit to normal Python interpreter. When you type 'help' repeatedly, your could run third, fourth, etc nested help utility.

Here is modified patch. Now help('help') produces the same output as help(help), but the 'help' request in interactive help utility prints help intro message.


>>> help('help')
Help on _Helper in module _sitebuiltins object:

help = class _Helper(builtins.object)
 |  Define the builtin 'help'.
 |  
 |  This is a wrapper around pydoc.help that provides a helpful message
 |  when 'help' is typed at the Python interactive prompt.
 |  
 |  Calling help() at the Python prompt starts an interactive help session.
 |  Calling help(thing) prints help for the python object 'thing'.
 |  
 |  Methods defined here:
 |  
 |  __call__(self, *args, **kwds)
 |  
 |  __repr__(self)
 |  
 |  ----------------------------------------------------------------------
 |  Data descriptors defined here:
 |  
 |  __dict__
 |      dictionary for instance variables (if defined)
 |  
 |  __weakref__
 |      list of weak references to the object (if defined)

>>> help()

Welcome to Python 3.5's help utility!

If this is your first time using Python, you should definitely check out
the tutorial on the Internet at http://docs.python.org/3.5/tutorial/.

Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules.  To quit this help utility and
return to the interpreter, just type "quit".

To get a list of available modules, keywords, symbols, or topics, type
"modules", "keywords", "symbols", or "topics".  Each module also comes
with a one-line summary of what it does; to list the modules whose name
or summary contain a given string such as "spam", type "modules spam".

help> help

Welcome to Python 3.5's help utility!

If this is your first time using Python, you should definitely check out
the tutorial on the Internet at http://docs.python.org/3.5/tutorial/.

Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules.  To quit this help utility and
return to the interpreter, just type "quit".

To get a list of available modules, keywords, symbols, or topics, type
"modules", "keywords", "symbols", or "topics".  Each module also comes
with a one-line summary of what it does; to list the modules whose name
or summary contain a given string such as "spam", type "modules spam".
help>
msg236918 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2015-02-28 22:13
LGTM.

I noticed this running the tests.

test_modules (test.test_pydoc.PydocImportTest) ... skipped 'causes undesireable side-effects (#20128)'
test_modules_search (test.test_pydoc.PydocImportTest) ... skipped 'causes undesireable side-effects (#20128)'
test_modules_search_builtin (test.test_pydoc.PydocImportTest) ... skipped 'some buildbots are not cooperating (#20128)'
msg236921 - (view) Author: Roundup Robot (python-dev) Date: 2015-02-28 22:43
New changeset 4a1fe339dcf6 by Serhiy Storchaka in branch 'default':
Issue #19980: Improved help() for non-recognized strings.  help('') now
https://hg.python.org/cpython/rev/4a1fe339dcf6
msg236922 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-02-28 22:46
Thank you for your contribution Mark.

> I noticed this running the tests.

This is temporary OK.
History
Date User Action Args
2015-02-28 22:46:58serhiy.storchakasetstatus: open -> closed
resolution: fixed
messages: + msg236922

stage: patch review -> resolved
2015-02-28 22:43:43python-devsetnosy: + python-dev
messages: + msg236921
2015-02-28 22:13:54BreamoreBoysetmessages: + msg236918
2015-02-28 19:25:48serhiy.storchakasetfiles: + issue19880v4.diff
2015-02-28 19:24:24serhiy.storchakasetfiles: - issue19880v4.diff
2015-02-28 19:22:19serhiy.storchakasetfiles: + issue19880v4.diff

nosy: + serhiy.storchaka
messages: + msg236903

assignee: docs@python -> serhiy.storchaka
2015-02-28 16:45:48BreamoreBoysetmessages: + msg236896
2015-01-28 19:56:42BreamoreBoysetmessages: + msg234910
2014-12-30 14:24:32BreamoreBoysetfiles: + issue19880v3.diff

messages: + msg233206
2014-11-22 13:57:36zach.waresetmessages: + msg231519
2014-11-22 08:05:14BreamoreBoysetmessages: + msg231514
2014-11-22 02:22:43zach.waresetmessages: + msg231507
2014-11-22 00:21:32BreamoreBoysetmessages: + msg231506
2014-10-26 16:57:09ezio.melottisetnosy: + ezio.melotti
2014-10-26 16:01:03BreamoreBoysetmessages: + msg230029
2014-07-28 18:43:15BreamoreBoysetfiles: + Issue19980.diff

messages: + msg224177
versions: + Python 3.5, - Python 3.4
2014-07-24 15:11:48zach.waresetmessages: + msg223847
2014-06-20 18:25:42terry.reedysetstage: needs patch -> patch review
2014-06-20 15:23:06BreamoreBoysetmessages: + msg221098
2014-06-03 17:13:12zach.waresetnosy: + zach.ware
2014-06-03 15:00:05BreamoreBoysetfiles: + issue19980.patch

messages: + msg219695
2014-05-26 17:45:52jesstesssetmessages: + msg219166
2014-05-26 14:20:19BreamoreBoysetmessages: + msg219154
2014-05-17 22:52:13BreamoreBoysetnosy: + BreamoreBoy
messages: + msg218721
2014-05-01 00:25:03eliassetmessages: + msg217668
2014-04-14 18:03:18terry.reedysetmessages: + msg216142
2014-04-14 14:43:48Jessica.McKellarsetnosy: + Jessica.McKellar, jesstess
messages: + msg216084
2014-03-04 04:52:19eliassetfiles: + empty-help-response.patch

messages: + msg212690
2014-02-03 15:40:15BreamoreBoysetnosy: - BreamoreBoy
2013-12-21 20:38:05eliassetfiles: + help-response.patch

nosy: + elias
messages: + msg206777

keywords: + patch
2013-12-14 01:47:06BreamoreBoysetnosy: + BreamoreBoy
messages: + msg206159
2013-12-14 01:34:52terry.reedycreate