[BUG]: Setting the `__name__` attribute changes the behaviour of error reporting
Maintainer thường phản hồi trong vòng 3 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
- 35/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Lĩnh vực
- backend-api-design
Hướng nghiên cứu
Tái hiện hành vi bằng binding example.cpp và phiên Python tương tác được hiển thị trong issue. Bắt đầu bằng cách đọc include/pybind11/detail/class.h và lần theo cách tên kiểu được chọn cho các lỗi thuộc tính; hoàn tất khi các lỗi vẫn được định danh kèm module khi name bị ghi đè, mà không thay đổi hành vi mặc định của Person.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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?
2.13.6
Problem description
Suppose that a class called Pet is implemented in a module called example. If an attribute reference fails, the error message is AttributeError: 'example.Pet' object has no attribute .... However, if the __name__ attribute is specified using pet.attr("__name__") = "PseudoPet"; then the attribute errors look like AttributeError: 'PseudoPet' object has no attribute .... Notice that, in the latter, there is no module name example.
I know that the PyTypeObject.tp_name member is different depending on whether the class/type was implemented in C or Python, and I think this gets used in include/pybind11/detail/class.h to determine various strings used for reporting. Perhaps this has something to do with the issue?
PEP 737 introduces some functions like PyType_GetModuleName(), and adds formats to PyUnicode_FromFormat() which may also be useful here?
Reproducible example code
In example.cpp:
#include <pybind11/pybind11.h>
namespace py = pybind11;
struct Pet {
Pet(const std::string &name) : name(name) {}
std::string name;
};
struct Person {
Person(const std::string &name) : name(name) {}
std::string name;
};
PYBIND11_MODULE(example, m) {
// Class with explicitly set __name__
py::class_<Pet> pet(m, "Pet");
pet.def(py::init<const std::string &>());
pet.attr("__name__") = "PseudoPet";
// Class with default name
py::class_<Person> person(m, "Person");
person.def(py::init<const std::string &>());
}
In an interactive Python session:
>>> from example import Pet, Person
>>> my_pet = Pet("John")
>>> my_pet.age
AttributeError: 'PseudoPet' object has no attribute 'age'
>>> my_person = Person("Jane")
>>> my_person.age
AttributeError: 'example.Person' object has no attribute 'age'
Is this a regression? Put the last known working version here if it is.
Not a regression
- Ngôn ngữ chính
- C++
- Star
- 18k
- Fork
- 2.3k
- Merge trung bình
- 5 ngày 7 giờ
- Pull request đã merge (30 ngày)
- 53
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
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 pybind/pybind11
-
triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 3 ngày
-
triage
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 62/100
pybind/pybind11#5604 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày
-
triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 3 ngày
-
docs
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 60/100
pybind/pybind11#747 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày
-
array_t::at() returns a misaligned reference when the stride is not a multiple of alignof(T)Có thể đã có người làm @henryiii đã nhận hôm nay. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
Maintainer thường phản hồi trong vòng 3 ngày
Tất cả issue của pybind/pybind11
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
patrick-hudson/put.gd-desktop#2044 ·
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 70/100
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 68/100
uxlfoundation/oneDNN#6604 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
[Bug]: RoundToNearest truncates in plugins compiled with spcomp 1.13Có thể đã có người làm @fmu1337 đã nhận hôm nay. Đang mởBug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
alliedmodders/sourcemod#2627 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
`Number` enum is not exportedĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày