python / python/cpython

Semantic and documentation of Interpreter.prepare_main()

Đang mở
#137,639 1 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ả

Interpreter.prepare_main() is documented as:

   .. method:: prepare_main(ns=None, **kwargs)
      
      Bind objects in the interpreter's :mod:`!__main__` module.
   
      Some objects are actually shared and some are copied efficiently,
      but most are copied via :mod:`pickle`.  See :ref:`interp-object-sharing`.

But it is not clear what ns is, and how kwargs is related. A module and a class are nemspaces, so can you pass them? Or the SimpleNamespace instance? No. Looking at the code, ns can only be None, a mapping or an iterable of pairs. Is it what was intended? Than it should be documented.

But accepting an iterable of pairs may be not intended. This can hardly be called a namespace. Then the code should be changed from

ns = dict(ns, **kwargs) if ns is not None else kwargs

to

ns = {**ns, **kwargs} if ns is not None else kwargs

And was it necessary to accept None? This is error-prone, as you can accidentally get None instead of a valid value (missing return or missing initialization). {} could be used as a default value, it is fine if it is not mutated. If exclude None, it can be simply written as:

ns = {**ns, **kwargs}

And I suggest to to change the name of the parameter, as it is not a general namespace. "dict" or "mapping" would better reflect its type. "updates" or "changes" could also be used, but then we should also rename "kwargs" to "updates2" or "changes2". Since this is positional-only parameter, changing the name does not break user code.

cc @ericsnowcurrently

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 tài liệu của Interpreter.prepare_main() và phần triển khai của nó, đặc biệt là cách ns và kwargs được kết hợp. Xác định các kiểu đầu vào được chấp nhận theo dự kiến và liệu tên tham số hoặc hành vi có nên thay đổi hay không, sau đó cập nhật tài liệu hoặc mã liên quan và thêm hoặc điều chỉnh các bài kiểm thử liên quan để ngữ nghĩa API được thể hiện rõ ràng.

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ó
4/5
Thời gian dự kiến
3-5 ngày
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
35/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.