diff --git a/tests/test_methods_and_attributes.cpp b/tests/test_methods_and_attributes.cpp index f433847c76..e324c8bdd4 100644 --- a/tests/test_methods_and_attributes.cpp +++ b/tests/test_methods_and_attributes.cpp @@ -294,7 +294,7 @@ TEST_SUBMODULE(methods_and_attributes, m) { static_cast( &ExampleMandA::overloaded)); }) - .def("__str__", &ExampleMandA::toString) + .def("__str__", &ExampleMandA::toString, py::pos_only()) .def_readwrite("value", &ExampleMandA::value); // test_copy_method diff --git a/tests/test_methods_and_attributes.py b/tests/test_methods_and_attributes.py index 91c7b7751e..cecc184647 100644 --- a/tests/test_methods_and_attributes.py +++ b/tests/test_methods_and_attributes.py @@ -19,6 +19,13 @@ ) +def test_self_only_pos_only(): + assert ( + m.ExampleMandA.__str__.__doc__ + == "__str__(self: pybind11_tests.methods_and_attributes.ExampleMandA, /) -> str\n" + ) + + def test_methods_and_attributes(): instance1 = m.ExampleMandA() instance2 = m.ExampleMandA(32)