Skip to content

Commit 39d30c8

Browse files
authored
fix: preserve help for wrapped pdb commands (#971)
1 parent a57904e commit 39d30c8

3 files changed

Lines changed: 36 additions & 7 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ releases are available on [PyPI](https://pypi.org/project/pytask) and
77

88
## Unreleased
99

10+
- [#971](https://github.com/pytask-dev/pytask/pull/971) restores help text for
11+
PDB commands wrapped by pytask.
1012
- [#970](https://github.com/pytask-dev/pytask/pull/970) prevents tee-sys capture from
1113
replaying output that was already displayed when capture stops before its buffer is
1214
read.

‎src/_pytask/debugging.py‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ def do_debug(self, arg: Any) -> None:
213213
cls._recursive_debug -= 1
214214
return ret
215215

216+
if hasattr(pdb_cls, "do_debug"):
217+
do_debug.__doc__ = pdb_cls.do_debug.__doc__
218+
216219
def do_continue(self, arg: Any) -> int:
217220
ret = super().do_continue(arg)
218221
if cls._recursive_debug == 0:
@@ -239,16 +242,17 @@ def do_continue(self, arg: Any) -> int:
239242
self._continued = True
240243
return ret
241244

245+
if hasattr(pdb_cls, "do_continue"):
246+
do_continue.__doc__ = pdb_cls.do_continue.__doc__
247+
242248
do_c = do_cont = do_continue
243249

244250
def do_quit(self, arg: Any) -> int:
245-
"""Raise Exit outcome when quit command is used in pdb.
246-
247-
This is a bit of a hack - it would be better if BdbQuit could be
248-
handled, but this would require to wrap the whole pytest run, and adjust
249-
the report etc.
250-
251-
"""
251+
# Raise Exit outcome when quit command is used in pdb.
252+
#
253+
# This is a bit of a hack - it would be better if BdbQuit could be
254+
# handled, but this would require to wrap the whole pytest run, and
255+
# adjust the report etc.
252256
ret = super().do_quit(arg)
253257

254258
if cls._recursive_debug == 0:
@@ -257,6 +261,9 @@ def do_quit(self, arg: Any) -> int:
257261

258262
return ret
259263

264+
if hasattr(pdb_cls, "do_quit"):
265+
do_quit.__doc__ = pdb_cls.do_quit.__doc__
266+
260267
do_q = do_quit
261268
do_exit = do_quit
262269

‎tests/test_debugging.py‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import os
4+
import pdb # noqa: T100
45
import re
56
import sys
67
import textwrap
@@ -9,6 +10,7 @@
910
import click
1011
import pytest
1112

13+
from _pytask.debugging import PytaskPDB
1214
from _pytask.debugging import _pdbcls_callback
1315
from pytask import ExitCode
1416
from pytask import cli
@@ -44,6 +46,24 @@ def test_capture_callback(value, expected, expectation):
4446
assert result == expected
4547

4648

49+
def test_pdb_wrapped_commands_keep_docstrings():
50+
class CustomPdb(pdb.Pdb):
51+
def do_debug(self, arg):
52+
"""Custom help for debug."""
53+
54+
def do_continue(self, arg):
55+
"""Custom help for continue."""
56+
57+
def do_quit(self, arg):
58+
"""Custom help for quit."""
59+
60+
wrapped = PytaskPDB._get_pdb_wrapper_class(CustomPdb, None, None) # type: ignore[arg-type]
61+
62+
assert wrapped.do_debug.__doc__ == CustomPdb.do_debug.__doc__
63+
assert wrapped.do_continue.__doc__ == CustomPdb.do_continue.__doc__
64+
assert wrapped.do_quit.__doc__ == CustomPdb.do_quit.__doc__
65+
66+
4767
def _flush(child):
4868
if child.isalive():
4969
child.read()

0 commit comments

Comments
 (0)