python / python/cpython

Removing unncessary class states in bdb.Breakpoint

Đang mở
#127,392 6 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:

According to the comment in the Breakpoint class

Keeping state in the class is a mistake -- this means you cannot have more than one active Bdb instance.

I can support this idea further. Currently, Breakpoint has three class states, next, bplist, and bpbynumber.

class Breakpoint:
    ...
    next = 1
    bplist = {}
    bpbynumber = [None]

These states are used to enable the reuse of previously set breakpoint instances across multiple interactive sessions or other use cases. However, relying on class states is not the only way to achieve this goal.

Using class states in this case has several clear limitations. As noted in the comment, it makes it difficult to maintain more than one active Bdb instance. Additionally, logic dependent on class state can make the behavior of a new Bdb instance unpredictable in many scenarios unless the exact states of Breakpoint is fully known. Another drawback of maintaining states in the Breakpoint class is that it tightly couples the behavior of all Bdb instances. For example, the deleteMe method must be called periodically by a Bdb instance to ensure the Breakpoint class remains in a valid state.

# example deleteMe calls in Bdb methods

class Bdb:
    ...
    def clear_break(self, filename, lineno):
        ...
        for bp in Breakpoint.bplist[filename, lineno][:]:
            bp.deleteMe()  # here
        self._prune_breaks(filename, lineno)
        return None
        
    def clear_bpbynumber(self, arg):
        ...
        try:
            bp = self.get_bpbynumber(arg)
        except ValueError as err:
            return str(err)
        bp.deleteMe()  # here
        self._prune_breaks(bp.file, bp.line)
        return None

As an alternative, instance-level state can be maintained within Bdb or derived classes such as Pdb, allowing each instance to manage its own breakpoint data independently. This approach can still support the reuse of previously set breakpoint instances across multiple interactive sessions.

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Linked PRs
  • gh-127410

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 Lib/bdb.py, đặc biệt là lớp Breakpoint và các phương thức Bdb được nêu trong issue, sau đó xem xét PR được liên kết gh-127410. Xác định trạng thái breakpoint hiện đang được chia sẻ giữa các thực thể Bdb như thế nào và quyền sở hữu ở cấp thực thể được đề xuất sẽ ảnh hưởng đến Bdb và Pdb ra sao. Được xem là hoàn tất khi thiết kế hỗ trợ các thực thể trình gỡ lỗi đang hoạt động độc lập mà không phụ thuộc vào trạng thái dùng chung của lớp Breakpoint.

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
devtools
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
Cần làm rõ
Mức phù hợp với người mới
20/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.