python / python/cpython

Avoid DeprecationWarning for `_pack_` without `_layout_` when there are not bit-fields?

未關閉
#133,800 4 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

extension-modules topic-ctypes type-bug
主要語言
Python
星號
77.2k
分支
36k
PR 合併指標
PR 指標待擷取

描述

Bug report

Bug description:

New Python versions give a DeprecationWarning for struct definitions that use _pack_ = True but do not specify the _layout_.

In a sense a new feature, but as I believe this is only relevant for bit-fields: wouldn't it make sense to allow leaving _layout_ unspecified when the struct contains no bitfields?
(I suppose that means giving it some default, such as the system native layout.)

The context is just seeing this in NumPy where bit-fields are not used so I was wondering: https://github.com/numpy/numpy/issues/28926.
Adding the _layout_ isn't a problem of course, but if the no-bitfield case is common (not sure) it may be nice to not be forced to "decide" on an irrelevant _layout_ (or act up on the DeprecationWarning)?

Another question that comes to mind is that _layout_ = "native" or so seems potentially useful.

CPython versions tested on:

3.14

Operating systems tested on:

Other

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

首先,在 Python 3.14 中重現針對使用 _pack_ = True 但沒有 _layout_ 的 struct 定義所產生的 DeprecationWarning,重點關注報告中描述的無位元欄位情況。檢視相關的 ctypes 行為以及報告中連結的 NumPy issue;完成的要求是確定一個一致認可的 layout 預設值,或明確決定該警告仍然是必要的。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python
領域
backend
Issue 類型
缺陷
難度
5/5
預估耗時
一週以上
活躍度
停滯
描述清晰度
需要釐清
新手友好度
25/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。