python / python/cpython

Docs: missing mention of bytes-like object in eval/exec() documentation

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

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

docs
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ả

Documentation
Documentation

In Doc/library/functions.rst, the sentences that describe the source parameter for the exec() function read:

This function supports dynamic execution of Python code. source must be either a string or a code object. If it is a string, the string is parsed as a suite of Python statements which is then executed (unless a syntax error occurs). [1]_ If it is a code object, it is simply executed.

This explicitly restricts the source parameter to a string or a code object. However, the actual implementation accepts bytes-like objects (such as bytes, bytearray, and memoryview) as well, parsing them internally via the buffer protocol. Because the sentence omits this, users can easily misunderstand that passing bytes is unsupported.

Suggested change

This function supports dynamic execution of Python code. source must be a string, a bytes-like object, or a code object. If it is a string or a bytes-like object, it is parsed as a suite of Python statements which is then executed (unless a syntax error occurs). [1]_ If it is a code object, it is simply executed.

Adding "a bytes-like object" makes the documentation accurately reflect the underlying implementation. Changing the subsequent sentence ensures logical consistency for how these types are parsed.

Linked PRs
  • gh-148943

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

Mở Doc/library/functions.rst và tìm phần tài liệu về exec() mô tả tham số source. So sánh cách diễn đạt với các trường hợp được hỗ trợ string, bytes-like object và code object được nêu trong issue. Hoàn thành khi tài liệu đề cập chính xác đến bytes-like objects và giải thích rằng strings và bytes-like objects được phân tích cú pháp.

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
documentation
Loại issue
Tài liệu
Độ khó
1/5
Thời gian dự kiến
Dưới một giờ
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Đặc tả 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.