Unpickling child class fails if base class __init_subclass__ expects an argument
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 42/100
Hướng nghiên cứu
Bắt đầu với reproducer trong issue và kiểm tra cloudpickle.py tại _make_skeleton_class, nơi traceback cho thấy lớp con Child được tạo lại. Theo dõi cách các đối số từ khóa của định nghĩa lớp được xử lý trong quá trình serialization và xác minh bản sửa bằng cách chạy lại ví dụ: cloudpickle phải unpickle Child thành công trong khi vẫn giữ nguyên giá trị arg của nó.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
If you have a base class that defines __init_subclass__ with an argument, unpickling a child class will fail because cloudpickle does not pass along the original kwarg when re-creating the class.
This case seems to work fine in the built-in pickle package.
This usage mirrors examples shown in the docs and the original PEP that introduced the __init_subclass__ method.
Python 3.11.4
cloudpickle 2.2.1
EDIT: This also appears to be broken with cloudpickle 3.0.0.
Example:
#!/usr/bin/env python3
import pickle
import cloudpickle
print(cloudpickle.__version__)
class Base:
def __init_subclass__(cls, /, arg, **kwargs):
super().__init_subclass__(**kwargs)
cls.arg = arg
class Child(Base, arg='hello'):
pass
print(pickle.loads(pickle.dumps(Base)))
print(pickle.loads(pickle.dumps(Child)))
print(cloudpickle.loads(cloudpickle.dumps(Base)))
print(cloudpickle.loads(cloudpickle.dumps(Child)))
2.2.1
<class '__main__.Base'>
<class '__main__.Child'>
<class '__main__.Base'>
Traceback (most recent call last):
File "/home/tsanders/test_cloudpickle_bug.py", line 20, in <module>
print(cloudpickle.loads(cloudpickle.dumps(Child)))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/conda/envs/production-3.11/lib/python3.11/site-packages/cloudpickle/cloudpickle.py", line 827, in _make_skeleton_class
skeleton_class = types.new_class(
^^^^^^^^^^^^^^^^
File "/opt/conda/envs/production-3.11/lib/python3.11/types.py", line 75, in new_class
return meta(name, resolved_bases, ns, **kwds)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: Base.__init_subclass__() missing 1 required positional argument: 'arg'
- Ngôn ngữ chính
- Python
- Star
- 1.9k
- Fork
- 198
- Merge trung bình
- 1 ngày 10 giờ
- Pull request đã merge (30 ngày)
- 1
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của cloudpipe/cloudpickle
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
cloudpipe/cloudpickle#593 · 1 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 42/100
cloudpipe/cloudpickle#595 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 65/100
cloudpipe/cloudpickle#592 · 2 bình luận ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
cloudpipe/cloudpickle#589 ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 20/100
cloudpipe/cloudpickle#587 ·
Tất cả issue của cloudpipe/cloudpickle
Issue tương tự
-
adr
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
kristofdegrave/homeassistant-smart-charging#1607 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
namespace operations
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
EclipseFdn/open-vsx.org#13665 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
doc good first issue help wanted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
collective/icalendar#1865 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
canonical/opentelemetry-collector-operator#409 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
mozilla/addons-release-tests#1243 ·
Maintainer thường phản hồi trong vòng 1 ngày