From 5c5b1b6e2e427eb0de3da957e89ea2234b46dce1 Mon Sep 17 00:00:00 2001 From: Tobias Raabe Date: Fri, 28 Aug 2026 23:00:21 +0200 Subject: [PATCH 1/2] fix: preserve help for wrapped pdb commands --- CHANGELOG.md | 1 + src/_pytask/debugging.py | 21 ++++++++++++++------- tests/test_debugging.py | 20 ++++++++++++++++++++ 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a49fd87d..65135009 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ releases are available on [PyPI](https://pypi.org/project/pytask) and ## Unreleased +- Restores help text for PDB commands wrapped by pytask. - [#968](https://github.com/pytask-dev/pytask/pull/968) improves the performance of file descriptor capture for tasks that produce no output. - Documents the pytest provenance of the adapted debugging, marker, and warning diff --git a/src/_pytask/debugging.py b/src/_pytask/debugging.py index 1484584e..abc63055 100644 --- a/src/_pytask/debugging.py +++ b/src/_pytask/debugging.py @@ -213,6 +213,9 @@ def do_debug(self, arg: Any) -> None: cls._recursive_debug -= 1 return ret + if hasattr(pdb_cls, "do_debug"): + do_debug.__doc__ = pdb_cls.do_debug.__doc__ + def do_continue(self, arg: Any) -> int: ret = super().do_continue(arg) if cls._recursive_debug == 0: @@ -239,16 +242,17 @@ def do_continue(self, arg: Any) -> int: self._continued = True return ret + if hasattr(pdb_cls, "do_continue"): + do_continue.__doc__ = pdb_cls.do_continue.__doc__ + do_c = do_cont = do_continue def do_quit(self, arg: Any) -> int: - """Raise Exit outcome when quit command is used in pdb. - - This is a bit of a hack - it would be better if BdbQuit could be - handled, but this would require to wrap the whole pytest run, and adjust - the report etc. - - """ + # Raise Exit outcome when quit command is used in pdb. + # + # This is a bit of a hack - it would be better if BdbQuit could be + # handled, but this would require to wrap the whole pytest run, and + # adjust the report etc. ret = super().do_quit(arg) if cls._recursive_debug == 0: @@ -257,6 +261,9 @@ def do_quit(self, arg: Any) -> int: return ret + if hasattr(pdb_cls, "do_quit"): + do_quit.__doc__ = pdb_cls.do_quit.__doc__ + do_q = do_quit do_exit = do_quit diff --git a/tests/test_debugging.py b/tests/test_debugging.py index b36f0366..9df520ba 100644 --- a/tests/test_debugging.py +++ b/tests/test_debugging.py @@ -1,6 +1,7 @@ from __future__ import annotations import os +import pdb # noqa: T100 import re import sys import textwrap @@ -9,6 +10,7 @@ import click import pytest +from _pytask.debugging import PytaskPDB from _pytask.debugging import _pdbcls_callback from pytask import ExitCode from pytask import cli @@ -44,6 +46,24 @@ def test_capture_callback(value, expected, expectation): assert result == expected +def test_pdb_wrapped_commands_keep_docstrings(): + class CustomPdb(pdb.Pdb): + def do_debug(self, arg): + """Custom help for debug.""" + + def do_continue(self, arg): + """Custom help for continue.""" + + def do_quit(self, arg): + """Custom help for quit.""" + + wrapped = PytaskPDB._get_pdb_wrapper_class(CustomPdb, None, None) # type: ignore[arg-type] + + assert wrapped.do_debug.__doc__ == CustomPdb.do_debug.__doc__ + assert wrapped.do_continue.__doc__ == CustomPdb.do_continue.__doc__ + assert wrapped.do_quit.__doc__ == CustomPdb.do_quit.__doc__ + + def _flush(child): if child.isalive(): child.read() From a64a6ad0a232050d97620b04db681d7d41492b12 Mon Sep 17 00:00:00 2001 From: Tobias Raabe Date: Fri, 28 Aug 2026 23:01:29 +0200 Subject: [PATCH 2/2] docs: link pdb help changelog entry --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 65135009..a5f087e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,8 @@ releases are available on [PyPI](https://pypi.org/project/pytask) and ## Unreleased -- Restores help text for PDB commands wrapped by pytask. +- [#971](https://github.com/pytask-dev/pytask/pull/971) restores help text for + PDB commands wrapped by pytask. - [#968](https://github.com/pytask-dev/pytask/pull/968) improves the performance of file descriptor capture for tasks that produce no output. - Documents the pytest provenance of the adapted debugging, marker, and warning