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.

classification
Title: help function reads comments
Type: behavior Stage: resolved
Components: Versions: Python 3.8
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: dam1784, steven.daprano
Priority: normal Keywords:

Created on 2022-01-22 01:38 by dam1784, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (2)
msg411218 - (view) Author: David Mc Dougall (dam1784) * Date: 2022-01-22 01:38
My inline comment ('#') got picked up by the help command.

Write the following code to a file (I named it "reproducer.py"):

"""

class Foo:
    # Hello docstring, I'm a '#' comment!
    def bar(self):
        pass

assert Foo.bar.__doc__ is None
help(Foo.bar)

"""

The bug only happens when the file is executed.
$ python3 reproducer.py

Help on function bar in module __main__:

bar(self)
    # Hello docstring, I'm a '#' comment!


Evaluating it at the interactive prompt does not reproduce the bug.
$ cat reproducer.py | python3

Help on function bar in module __main__:

bar(self)
msg411221 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2022-01-22 02:34
That's not a bug.

https://docs.python.org/3/library/pydoc.html

"If there is no docstring, pydoc tries to obtain a description from the block of comment lines just above the definition of the class, function or method in the source file, or at the top of the module (see inspect.getcomments())."
History
Date User Action Args
2022-04-11 14:59:55adminsetgithub: 90624
2022-01-22 02:34:41steven.dapranosetstatus: open -> closed

nosy: + steven.daprano, dam1784
messages: + msg411221

resolution: not a bug
stage: resolved
2022-01-22 01:38:49dam1784setnosy: - dam1784
-> (no value)
2022-01-22 01:38:03dam1784create