[BUG]: `tp_name` field not initialized correctly for a nested class

オープン
#5,132 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 4 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
42/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
cpp, python
領域
api

調査の方向性

include/pybind11/detail/class.h の make_new_python_type() から始め、issue で説明されているネストされた Pet.Attributes のケースを再現し、生成された PyTypeObject の名前を確認します。Python のエラーがオブジェクトを mymodule.Attributes ではなく mymodule.Pet.Attributes として識別すれば完了です。

索引モデルが issue の本文から書いたものです。

説明

triage
Required prerequisites
What version (or hash if on master) of pybind11 are you using?

2.11.1

Problem description

Consider the following bindings for a class Pet and some nested class Pet.Attributes, whichs is taken from the pybind11 docs:

py::class_<Pet> pet(m, "Pet");

py::class_<Pet::Attributes>(pet, "Attributes")
    .def(py::init<>());

pybind11 seems to be computing a wrong tp_name field for the nested class' PyTypeObject in make_new_python_type(). The class ends up being named just mymodule.Attributes instead of the expected mymodule.Pet.Attributes.

This can be demonstrated: The Python interpreter uses the wrong tp_name in error messages, for example:

import mymodule
a = mymodule.Pet.Attributes()
print(a.nonexisting)

gives the following error string:

AttributeError: 'mymodule.Attributes' object has no attribute 'nonexisting'

Please let me know if you also think this needs to be fixed. If so, I would be willing to contribute a pull request.

Reproducible example code

No response

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

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

pybind/pybind11 のほかの issue

pybind/pybind11 の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。