Globals read only inside a class body defined in a by-value function are not pickled (NameError after loading)
Maintainer thường phản hồi trong vòng 9 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 55/100
Hướng nghiên cứu
Start by reading _extract_code_globals around GLOBAL_OPS in cloudpickle/cloudpickle.py, then inspect _function_getstate and the base_globals path in _function_getnewargs identified in the issue. Reproduce the provided example and check the related class-scope opcode cases across the listed Python versions. Done means the globals used by those class scopes are available after loading, with regression tests covering the reported cases.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
🤖 AI text below 🤖
A global that a by-value function reads only inside the body of a class it defines is not pickled, so the loaded function raises NameError. This happens on Python 3.11 through 3.14, with cloudpickle 3.1.2 and with master (4af5936).
import subprocess, sys
import cloudpickle
ns = {"__name__": "not_importable", "CONST": 42} # not importable, so f is pickled by value
exec("def f():\n class Rec:\n q = CONST\n return Rec.q\n", ns)
print("local:", ns["f"]())
load = "import pickle, sys; print(pickle.loads(sys.stdin.buffer.read())())"
r = subprocess.run([sys.executable, "-c", load], input=cloudpickle.dumps(ns["f"]), capture_output=True)
print("loaded:", (r.stdout or r.stderr).decode().strip().splitlines()[-1])
Output on 3.11.15, 3.12.10, 3.13.3 and 3.14.6:
local: 42
loaded: NameError: name 'CONST' is not defined
Other class-scope reads fail the same way:
- a field annotation naming a global, for example a dataclass
p: Pointdefined inside the function (measured on 3.13 and 3.14); - a class-scoped
type Inner = Galias, once its value is evaluated (measured on 3.12, 3.13 and 3.14).
Cause: _extract_code_globals only collects names from GLOBAL_OPS, which is STORE_GLOBAL, DELETE_GLOBAL and LOAD_GLOBAL (L388-L397). Inside a class scope, the compiler reads names with other opcodes (measured with dis):
- class-body statements, and annotations before 3.14, use
LOAD_NAME(3.11-3.14); - a class's
__annotate__function (3.14) and a class-scopedtypealias value (3.12+) useLOAD_FROM_DICT_OR_GLOBALS.
Suggested fix: add LOAD_NAME to GLOBAL_OPS, and also LOAD_FROM_DICT_OR_GLOBALS on 3.12+. Both consumers already keep only names present in func.__globals__, so class-local names collected this way are dropped:
_function_getstate(L734-L735);- the
base_globalspath in_function_getnewargs(L1307-L1314).
Related: #608.
- Ngôn ngữ chính
- Python
- Star
- 1.9k
- Fork
- 201
- 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
-
Bug: unguarded dict.pop() in _function_setstate causes KeyError crash on crafted pickle (regression from c6f8cd4)Có thể đã có người làm @soodoku đã nhận 78 ngày trước. Đang mở
Độ 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 ·
Maintainer thường phản hồi trong vòng 9 ngày
-
A class pickled by value before its annotations are read loses them.Có thể đã có người làm @pralav-25 đã nhận 4 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 67/100
cloudpipe/cloudpickle#608 ·
Maintainer thường phản hồi trong vòng 9 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 42/100
cloudpipe/cloudpickle#595 ·
Maintainer thường phản hồi trong vòng 9 ngày
-
cloudpickle is not compatible with PyPy 7.3.22Có thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ 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 ·
Maintainer thường phản hồi trong vòng 9 ngày
-
Độ 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 ·
Maintainer thường phản hồi trong vòng 9 ngày
Tất cả issue của cloudpipe/cloudpickle
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
aws-samples/sample-per-model-bedrock#191 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area: docs enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
PyTomography/PyTomography#331 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
effort: low prio: low ready
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
digitalfabrik/integreat-cms#4616 ·
Maintainer thường phản hồi trong vòng 5 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
FuRongJun-1999/dsh-memory#226 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug difficulty:2 good first issue help wanted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
MakazhanAlpamys/Soup#1865 ·
Maintainer thường phản hồi trong vòng 1 ngày