Skip to content

Add __qualname__ tests #5775

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion tests/test_class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,16 +477,20 @@ TEST_SUBMODULE(class_, m) {
// test_qualname
// #1166: nested class docstring doesn't show nested name
// Also related: tests that __qualname__ is set properly
m.def("module_func", []() {});
struct NestBase {};
struct Nested {};
py::class_<NestBase> base(m, "NestBase");
base.def(py::init<>());
py::class_<Nested>(base, "Nested")
.def(py::init<>())
.def("fn", [](Nested &, int, NestBase &, Nested &) {})
.def("fa", [](Nested &, int, NestBase &, Nested &) {}, "a"_a, "b"_a, "c"_a);
.def(
"fa", [](Nested &, int, NestBase &, Nested &) {}, "a"_a, "b"_a, "c"_a)
.def_static("static_func", []() {});
base.def("g", [](NestBase &, Nested &) {});
base.def("h", []() { return NestBase(); });
base.def_static("static_func", []() {});

// test_error_after_conversion
// The second-pass path through dispatcher() previously didn't
Expand Down
6 changes: 6 additions & 0 deletions tests/test_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@
assert m.NestBase.__qualname__ == "NestBase"
assert m.NestBase.Nested.__qualname__ == "NestBase.Nested"

assert m.module_func.__qualname__ == "module_func"

Check failure on line 145 in tests/test_class.py

View workflow job for this annotation

GitHub Actions / 🐍 (ubuntu-22.04, 3.8, -DPYBIND11_FINDPYTHON=OFF -DPYBIND11_NUMPY_1_ONLY=ON) / 🧪

test_qualname AssertionError: assert 'pybind11_det...1.module_func' == 'module_func' - module_func + pybind11_detail_function_record_v1_system_libstdcpp_gxx_abi_1xxx_use_cxx11_abi_1.module_func

Check failure on line 145 in tests/test_class.py

View workflow job for this annotation

GitHub Actions / 🐍 (ubuntu-latest, graalpy-24.2, -DCMAKE_CXX_STANDARD=20) / 🧪

test_qualname AssertionError: assert 'pybind11_det...1.module_func' == 'module_func' - module_func + pybind11_detail_function_record_v1_system_libstdcpp_gxx_abi_1xxx_use_cxx11_abi_1.module_func

Check failure on line 145 in tests/test_class.py

View workflow job for this annotation

GitHub Actions / 🐍 (ubuntu-latest, 3.13, -DCMAKE_CXX_STANDARD=23 -DPYBIND11_SIMPLE_GIL_MANAGEMENT=ON) / 🧪

test_qualname AssertionError: assert 'pybind11_det...1.module_func' == 'module_func' - module_func + pybind11_detail_function_record_v1_system_libstdcpp_gxx_abi_1xxx_use_cxx11_abi_1.module_func

Check failure on line 145 in tests/test_class.py

View workflow job for this annotation

GitHub Actions / 🐍 (ubuntu-latest, 3.14t, -DCMAKE_CXX_STANDARD=17 -DPYBIND11_TEST_SMART_HOLDER=ON) / 🧪

test_qualname AssertionError: assert 'pybind11_det...1.module_func' == 'module_func' - module_func + pybind11_detail_function_record_v1_system_libstdcpp_gxx_abi_1xxx_use_cxx11_abi_1.module_func
assert m.NestBase.g.__qualname__ == "NestBase.g"

Check failure on line 146 in tests/test_class.py

View workflow job for this annotation

GitHub Actions / 🐍 (ubuntu-latest, pypy3.11, -DCMAKE_CXX_STANDARD=17) / 🧪

test_qualname AttributeError: 'cinstancemethod' object has no attribute '__qualname__'
assert m.NestBase.static_func.__qualname__ == "NestBase.static_func"
assert m.NestBase.Nested.fn.__qualname__ == "NestBase.Nested.fn"
assert m.NestBase.Nested.static_func.__qualname__ == "NestBase.Nested.static_func"

assert (
doc(m.NestBase.__init__)
== """
Expand Down
Loading