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: pdb help fails with AttributeError when using Windows embeddable package
Type: Stage: resolved
Components: Library (Lib), Windows Versions: Python 3.11, Python 3.10, Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: miss-islington, paul.moore, sparrowt, steve.dower, tim.golden, zach.ware
Priority: normal Keywords: patch

Created on 2022-01-19 16:41 by sparrowt, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 30705 merged sparrowt, 2022-01-19 17:44
PR 30754 merged miss-islington, 2022-01-21 17:01
PR 30755 closed miss-islington, 2022-01-21 17:01
PR 30759 merged miss-islington, 2022-01-21 19:06
Messages (11)
msg410970 - (view) Author: (sparrowt) * Date: 2022-01-19 16:41
When running python from an embeddable windows zip file such as:
https://www.python.org/ftp/python/3.9.10/python-3.9.10-embed-amd64.zip

the `help` command within `pdb` is broken due to missing docstrings, as demonstrated below.

Python 3.9.10 (tags/v3.9.10:f2f3f53, Jan 17 2022, 15:14:21) [MSC v.1929 64 bit (AMD64)] on win32
>>> import pdb
>>> pdb.set_trace()
--Return--
> <stdin>(1)<module>()->None
(Pdb) help interact
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "bdb.py", line 92, in trace_dispatch
  File "bdb.py", line 151, in dispatch_return
  File "pdb.py", line 294, in user_return
  File "pdb.py", line 357, in interaction
  File "pdb.py", line 322, in _cmdloop
  File "cmd.py", line 138, in cmdloop
  File "pdb.py", line 422, in onecmd
  File "cmd.py", line 217, in onecmd
  File "pdb.py", line 1496, in do_help
AttributeError: 'NoneType' object has no attribute 'rstrip'
>>>
>>> print(pdb.Pdb.do_interact.__doc__)
None
msg410971 - (view) Author: (sparrowt) * Date: 2022-01-19 16:43
Perhaps we should have a more generic check for `command.__doc__` as it appears this is a case not handled by the existing `sys.flags.optimize >= 2` check?

https://github.com/python/cpython/blob/v3.9.10/Lib/pdb.py#L1492-L1496
msg410977 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2022-01-19 19:39
The PR looks good. I assume you've started the CLA process, so once that clears we'll be fine to merge.
msg411016 - (view) Author: (sparrowt) * Date: 2022-01-20 10:15
Thanks, yes CLA should now be working its way through the system.

I guess a side question is: is it expected for docstring to have been stripped from the windows embeddable distribution, and how is that done if not with -OO? (I found --without-doc-strings but not any build scripts using it)

This patch is still valid either way I think - better to show a helpful error than to explode - but I am intrigued as to the reason behind this case, deliberate or not. e.g. is there an assumption that the embed redistributable is never going to be used interactively & thus we might as well save space?
msg411024 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2022-01-20 13:07
See https://github.com/python/cpython/blob/b04dfbbe4bd7071d46c8688c2263726ea31d33cd/PC/layout/main.py#L256-L289

Basically, the .pyc files in the embeddable distro have been compiled with optimize=2, which is the equivalent of -OO. So yes, docstrings (and asserts) are expected to have been removed.

It shouldn't be removing docstrings from other modules that you provide yourself.
msg411026 - (view) Author: (sparrowt) * Date: 2022-01-20 14:15
Gottit thanks for explaining - so the existing check in `do_help` didn't catch this case because https://docs.python.org/3/library/sys.html#sys.flags only reflects command line flags, rather than whether or not it was actually optimised.
msg411027 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2022-01-20 14:20
> the existing check in `do_help` didn't catch this case because https://docs.python.org/3/library/sys.html#sys.flags only reflects command line flags, rather than whether or not it was actually optimised.

Precisely. Your check is much more appropriate for what the actual issue 
is going to be, though keeping the existing check there means we can 
provide a more specific error message when we *know* that the user 
deliberately chose that behaviour.
msg411149 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2022-01-21 17:01
New changeset 60705cff70576482fea31dcafbf8a37cbb751ea5 by Tom Sparrow in branch 'main':
bpo-46434: Handle missing docstrings in pdb help (GH-30705)
https://github.com/python/cpython/commit/60705cff70576482fea31dcafbf8a37cbb751ea5
msg411159 - (view) Author: miss-islington (miss-islington) Date: 2022-01-21 17:33
New changeset c3ad850b57f92bd7c5515616b59afbd9e1c79538 by Miss Islington (bot) in branch '3.9':
bpo-46434: Handle missing docstrings in pdb help (GH-30705)
https://github.com/python/cpython/commit/c3ad850b57f92bd7c5515616b59afbd9e1c79538
msg411175 - (view) Author: miss-islington (miss-islington) Date: 2022-01-21 19:32
New changeset 05063fa15c594012e6dc9c2c7a3ea72e7cb933f2 by Miss Islington (bot) in branch '3.10':
bpo-46434: Handle missing docstrings in pdb help (GH-30705)
https://github.com/python/cpython/commit/05063fa15c594012e6dc9c2c7a3ea72e7cb933f2
msg411176 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2022-01-21 19:43
Thanks for the contribution!
History
Date User Action Args
2022-04-11 14:59:54adminsetgithub: 90592
2022-01-21 19:43:19steve.dowersetstatus: open -> closed
resolution: fixed
messages: + msg411176

stage: patch review -> resolved
2022-01-21 19:32:58miss-islingtonsetmessages: + msg411175
2022-01-21 19:06:38miss-islingtonsetpull_requests: + pull_request28946
2022-01-21 17:33:28miss-islingtonsetmessages: + msg411159
2022-01-21 17:01:23miss-islingtonsetpull_requests: + pull_request28942
2022-01-21 17:01:07steve.dowersetmessages: + msg411149
2022-01-21 17:01:02miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request28941
2022-01-20 14:20:11steve.dowersetmessages: + msg411027
2022-01-20 14:15:56sparrowtsetmessages: + msg411026
2022-01-20 13:07:13steve.dowersetmessages: + msg411024
2022-01-20 10:15:44sparrowtsetmessages: + msg411016
2022-01-19 19:39:43steve.dowersetmessages: + msg410977
versions: - Python 3.7, Python 3.8
2022-01-19 17:44:18sparrowtsetkeywords: + patch
stage: patch review
pull_requests: + pull_request28901
2022-01-19 16:43:46sparrowtsetmessages: + msg410971
2022-01-19 16:41:48sparrowtcreate