[BUG]: Objects created using __new__ are not registered for casting
メンテナーはふだん 3 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 45/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 静か
調査の方向性
まず、再現可能な C++ pybind11 の例を構築し、Num、MoreNum、new、mult2、mult4 に関する、示されている Python 呼び出しを実行します。new を通じて作成された py::class_ オブジェクトが pybind11 オブジェクトレジストリに入る仕組みを追跡します。完了条件は、これらのオブジェクトが登録され、チェーンされた呼び出しで実際のサブタイプの動作が維持されることです。
索引モデルが issue の本文から書いたものです。
説明
Required prerequisites
- Make sure you've read the documentation. Your issue may be addressed there.
- Search the issue tracker and Discussions to verify that this hasn't already been reported. +1 or comment there if it has.
- Consider asking first in the Gitter chat room or in a Discussion.
What version (or hash if on master) of pybind11 are you using?
3.0.1
Problem description
When a pybind-based object or a subclass of one is created using new, it is not added to the registry of pybind objects for casting. If the object has methods than require casting to return the correct type information for its actual subtype, then this silently breaks those methods.
This is somewhat related to issue #1693, as using the listed workaround is how I found this problem.
Reproducible example code
Suppose we have:
#include <pybind11/pybind11.h>
using namespace py = pybind11;
struct Num {
double n;
Num(double n) : n(n) {}
inline Num Mult2() { return Num(2 * n) }
}
PYBIND11_MODULE(this_example, m) {
py::class_<Num> pyNum(m, "Num");
pyNum
.def(py::init([]() { return Num(0); }))
.def("mult2", [](const Num *self) {
py::object selfObj = py::cast(self);
PyTypeObject *const ty = Py_TYPE(selfObj.ptr());
auto newObj = py::reinterpret_steal<py::object>(ty->tp_new(ty, py::list().ptr(), py::dict().ptr()));
*newObj.cast<Num*>() = self->Mult2();
return newObj;
})
.def_readwrite("n", &Num::n);
}
from this_example import Num
class MoreNum(Num):
def mult4(self):
ret = self.__class__.__new__(self.__class__)
ret.n = self.n * self.n
return ret
# Works, but returned object is not registered.
MoreNum().mult2()
MoreNum().mult4()
MoreNum().mult2().mult4()
# mult4 is not implemented on Num
MoreNum().mult2().mult2().mult4()
Is this a regression? Put the last known working version here if it is.
Not a regression
- 主要言語
- C++
- スター
- 18k
- フォーク
- 2.3k
- 平均マージ
- 5日 7時間
- マージ済み PR(30日)
- 53
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
pybind/pybind11 のほかの issue
-
triage
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 3 日以内に返信
-
triage
難易度 1/5 1時間未満 初心者へのやさしさ 62/100
pybind/pybind11#5604 · コメント 1 件 ·
メンテナーはふだん 3 日以内に返信
-
triage
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 3 日以内に返信
-
docs
難易度 2/5 1〜3時間 初心者へのやさしさ 60/100
pybind/pybind11#747 · コメント 2 件 ·
メンテナーはふだん 3 日以内に返信
-
array_t::at() returns a misaligned reference when the stride is not a multiple of alignof(T)対応中かも @henryiii が今日担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
メンテナーはふだん 3 日以内に返信
pybind/pybind11 の issue をすべて見る
似ている issue
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
raspberrypi/rpi-imager#1804 ·
-
difficulty: easy docs good first issue help wanted
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
Ryan-Millard/Img2Num#842 ·
メンテナーはふだん 12 日以内に返信
-
Unit converter reads out of bounds when the saved UnitConverterPreferences setting is malformedオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
microsoft/calculator#2532 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 64/100
-
bug difficulty:easy prio:normal
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
NatronGitHub/openfx-misc#411 ·
メンテナーはふだん 1 日以内に返信