python / python/cpython

Specify skip= parameters to pdb.Pdb from command line or .pdbrc

Đang mở
#157,777 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

stdlib type-feature
Ngôn ngữ chính
Python
Star
77.2k
Fork
35.9k
Chỉ số merge pull request
Chỉ số pull request đang chờ

Mô tả

Feature or enhancement

Proposal:
Problem

pdb.Pdb accepts a skip parameter containing glob-style module-name patterns:

pdb.Pdb(skip=["django.*", "some_package.generated.*"])

However, this existing functionality cannot be configured when invoking pdb through its command-line interface:

python -m pdb -m some_package.module

It also cannot be configured cleanly from .pdbrc. Commands from .pdbrc execute in the context of the debugged frame, and there is no documented reference to the active pdb.Pdb instance.

The current workaround requires accessing pdb implementation details:

!import sys; _pdb = sys._getframe(1).f_locals["self"]; _pdb.skip = {"some_package.*"}

This depends on the internal call stack and the local variable name used by pdb, so it is unsuitable as a supported configuration mechanism.

Proposed behavior

Expose Pdb(skip=...) through both the command-line interface and pdb commands.

For example, allow a repeatable --skip option:

python -m pdb \
    --skip "django.*" \
    --skip "some_package.generated.*" \
    -m some_package.module

The collected patterns would be passed to the existing Pdb(skip=...) parameter.

Additionally, add a debugger command that can be used interactively, through -c, or from .pdbrc:

skip django.* some_package.generated.*

For example, .pdbrc could contain:

skip asyncio.*
skip concurrent.futures.*

Invoking the command without arguments could display the currently configured patterns:

(Pdb) skip
Skipped module patterns:
  asyncio.*
  concurrent.futures.*

There should also be a supported way to remove patterns, such as:

unskip asyncio.*

The exact command syntax is open to discussion. The important part is providing a supported route from the CLI and .pdbrc to the existing Pdb.skip functionality.

Standard-library convenience

A --skip-stdlib option and corresponding .pdbrc command would also be useful:

python -m pdb --skip-stdlib -m some_package.module

skip stdlib

On Python versions that provide sys.stdlib_module_names, this could be implemented using patterns for both the top-level modules and their submodules.

Standard-library skipping should remain opt-in because users may need to debug standard-library code, and an application module can shadow a standard-library module name.

Rationale

Module skipping is particularly useful when stepping through application code that calls into frameworks, generated modules, or the standard library. The underlying debugger has supported this since the addition of the skip parameter, but that capability is effectively unavailable to users of the standard python -m pdb workflow.

Exposing it would:

  • Make Pdb(skip=...) usable from the normal pdb CLI.

  • Allow project-specific skip configuration in .pdbrc.

  • Eliminate reliance on private frame and local-variable details.

  • Permit skip patterns to be inspected and changed during a debugging session.

  • Preserve the existing behavior by making all skipping opt-in.

Current workaround

For reference, the workaround currently required in .pdbrc is similar to:

!import sys; _pdb = sys._getframe(1).f_locals["self"]; _pdb.skip = (_pdb.skip or set()) | {"some_package.*"}; del _pdb

The need to reach into sys._getframe(1).f_locals to configure an already-supported Pdb option indicates that the command-line interface is missing an appropriate configuration mechanism.

Skipping stdlib through .pdbrc

!import sys; _pdb = sys._getframe(1).f_locals\["self"\]; _pdb.skip = (_pdb.skip or set()) | {"click.\*"} | {p for n in sys.stdlib_module_names for p in (n, n + ".*")}; del _pdb;

Why not use IPython’s debugger, an IDE, or another debugger?

Third-party debuggers and IDE integrations may provide similar stepping filters or more extensive configuration. However, they are not always available in the environments where pdb is most valuable.

My primary development environment is an air-gapped system. It currently uses Python 3.10 and is expected to move to Python 3.14, but upgrades are irregular and installing an additional debugger package is not always possible. Every additional dependency must be acquired, reviewed, approved, transferred, and maintained within the isolated environment.

I also frequently work through SSH, including on remote systems where a graphical IDE or its remote-debugging integration is unavailable or impractical. In these situations, the standard-library pdb CLI is the most portable and consistently available debugger:

python -m pdb -m package.module

This proposal does not attempt to reproduce the broader functionality of IPython, ipdb, IDE debuggers, or other third-party tools. It exposes functionality that pdb.Pdb already implements through the standard python -m pdb interface. Users should not need an additional package or graphical development environment merely to supply the existing skip= parameter.


Disclosure: I used an AI assistant to help draft and organize this feature proposal. I reviewed and edited the resulting text, and the proposal reflects the behavior and use case I encountered.

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

https://discuss.python.org/t/specify-skip-parameters-to-pdb-pdb-from-command-line-or-pdbrc/109042/3

Linked PRs
  • gh-157780

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với entry point python -m pdb, tham số Pdb(skip=...) hiện có và cách xử lý lệnh .pdbrc. Xem lại thảo luận được liên kết trong issue và PR gh-157780 trước khi quyết định phạm vi. Phần hoàn thành cần cung cấp một cách được hỗ trợ để cấu hình, kiểm tra và xóa các mẫu skip thông qua CLI và các lệnh của debugger.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
cli, developer-experience
Loại issue
Tính năng
Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
25/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.