I'm not sure about the convention here, but after searching through the pydoc
code I would like to provide a more detailed answer to my own question (the pydoc
help text is not very informative on the details). The
When passed an argument with type matching type("")
, help
checks to see if the argument is:
- in the list ['keywords', 'symbols', 'topics', 'modules', 'modules *', 'True', 'False', 'None'];
- a keyword (e.g. "from");
- a symbol (e.g. '%',
'<');
- a topic (e.g. 'FUNCTIONS', 'METHODS');
This is done in the pydoc.Helper.help
method. If a match is found, some specific help text is returned.
If none of the above conditions hold, the program flow continues and the object is passed via pydoc.render_doc
to the pydoc.resolve
function. Here, if the object is an instance of str
(including instances of sub-classes, as interpreted by the built-in function isinstance
, the pydoc.resolve
function attempts to locate a module defined by the value of the argument, and raises an ImportError
exception if there is none.
Hence, help('METHODS')
provides help on python methods, while help(Cls1('METHODS'))
returns an error (where Cls1
is as defined in the question).
This explains the behaviour I see. To me, the use of the isinstance
test in pydoc.resolve
, as opposed to the type("")
test used in pydoc.Helper.help
, appears to be an unnecessary inconsistency. There could, of course, be many reasons for this that I'm not aware of, so I've raised a new question focussed on this issue here.