Improvements Related to Namespace Package Portions for PathEntryFinders

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

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

Đánh giá

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

Hướng nghiên cứu

Bắt đầu với mục tài liệu về PathEntryFinder.find_spec() và phần language-reference namespace-packages được liên kết trong issue. Đọc bối cảnh của PEP 420 và PEP 451, sau đó xem xét các phương án chưa được giải quyết để xác định các phần và xử lý dữ liệu Spec bổ sung. Công việc được xem là hoàn tất khi hành vi do dự án lựa chọn được ghi chép rõ ràng và mọi thay đổi hành vi liên quan đã được thống nhất trước khi triển khai.

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

Mô tả

interpreter-core topic-importlib type-feature

tl;dr there are some oddities we should consider addressing with namespace package portions coming from path entry finders. It probably isn't worth bothering though (except for the docs fixes).


PEP 420 added (implicit) namespace packages. At that time, and since then, namespace packages (and portions) have gotten special-casing throughout the import machinery. Generally, we treat them like normal modules (or specs) even though certain characteristics don't apply. This isn't a problem generally because namespace packages aren't that common (and because, I expect, only builtin importers ever deal with them). However, there are a few things that it might be worth addressing.

PEP 451 introduced ModuleSpec, etc. PathEntryFinder.find_spec() as the replacement for PathEntryFinder.find_loader(), with some notable differences:

  • find_loader() returns (loader, portion)
    • the interpretation of this value is clearly documented
    • the finder can't provide any other possible information
    • if the returned loader is not None then the portion is ignored (not even a warning is set)
  • find_spec() returns a ModuleSpec with loader set to None and submodule_search_locations set to the portion
    • the interpretation of this value for portions is not clearly documented anywhere
    • the path entry finder may set addition info on the spec (e.g. loader_state) but it is all ignored (not even a warning if set)

In both cases, the language reference is not clear about how to identify namespace package portions from a path entry finder.

What to Do?

  • update the PathEntryFinder.find_spec() docs entry
  • (a weak maybe) add the details to the language reference
  • (maybe) be more explicit when returning a namespace package portion
  • (maybe) strictly disallow (or warn) for extraneous information tied to a portion
explicitly identify namespace package portions
  1. do nothing
  2. use a dedicated singleton instead of None
  3. use a dedicated ModuleSpec subclass (e.g. NamespacePackagePortionSpec)
  4. use a dedicated ModuleSpec-compatible class (e.g. NamespacePackagePortionSpec)
explicitly deal with unexpectedly set data

(This is basically just if spec.origin is set.)

  1. do nothing
  2. emit a warning
  3. fail
explicitly deal with spec.loader_state
  1. do nothing
  2. emit a warning
  3. fail
  4. preserve the info on the spec of the combined namespace package
Ngôn ngữ chính
Python
Star
77.2k
Fork
36k
Merge trung bình
1 ngày 9 giờ
Pull request đã merge (30 ngày)
558

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.

Issue khác của python/cpython

Tất cả issue của python/cpython

Issue tương tự

Thêm issue về Python

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.