MCPcopy Create free account
hub / github.com/pybind/pybind11 / PYBIND11_MODULE

Function PYBIND11_MODULE

tests/pybind11_tests.cpp:78–141  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

76}
77
78PYBIND11_MODULE(pybind11_tests, m, py::mod_gil_not_used()) {
79 m.doc() = "pybind11 test module";
80
81 // Intentionally kept minimal to not create a maintenance chore
82 // ("just enough" to be conclusive).
83#if defined(__VERSION__)
84 m.attr("compiler_info") = __VERSION__;
85#elif defined(_MSC_FULL_VER)
86 m.attr("compiler_info") = "MSVC " PYBIND11_TOSTRING(_MSC_FULL_VER);
87#else
88 m.attr("compiler_info") = py::none();
89#endif
90 m.attr("cpp_std") = cpp_std();
91 m.attr("PYBIND11_INTERNALS_ID") = PYBIND11_INTERNALS_ID;
92 // Free threaded Python uses UINT32_MAX for immortal objects.
93 m.attr("PYBIND11_SIMPLE_GIL_MANAGEMENT") =
94#if defined(PYBIND11_SIMPLE_GIL_MANAGEMENT)
95 true;
96#else
97 false;
98#endif
99 m.attr("PYBIND11_TEST_SMART_HOLDER") =
100#if defined(PYBIND11_RUN_TESTING_WITH_SMART_HOLDER_AS_DEFAULT_BUT_NEVER_USE_IN_PRODUCTION_PLEASE)
101 true;
102#else
103 false;
104#endif
105
106 bind_ConstructorStats(m);
107
108#if defined(PYBIND11_DETAILED_ERROR_MESSAGES)
109 m.attr("detailed_error_messages_enabled") = true;
110#else
111 m.attr("detailed_error_messages_enabled") = false;
112#endif
113
114#if defined(__cpp_noexcept_function_type)
115 m.attr("defined___cpp_noexcept_function_type") = true;
116#else
117 m.attr("defined___cpp_noexcept_function_type") = false;
118#endif
119
120 py::class_<UserType>(m, "UserType", "A `py::class_` type for testing")
121 .def(py::init<>())
122 .def(py::init<int>())
123 .def("get_value", &UserType::value, "Get value using a method")
124 .def("set_value", &UserType::set, "Set value using a method")
125 .def_property("value", &UserType::value, &UserType::set, "Get/set value using a property")
126 .def("__repr__", [](const UserType &u) { return "UserType({})"_s.format(u.value()); });
127
128 py::class_<IncType, UserType>(m, "IncType")
129 .def(py::init<>())
130 .def(py::init<int>())
131 .def("__repr__", [](const IncType &u) { return "IncType({})"_s.format(u.value()); });
132
133 for (const auto &initializer : initializers()) {
134 initializer(m);
135 }

Callers

nothing calls this directly

Calls 7

noneClass · 0.85
cpp_stdFunction · 0.85
bind_ConstructorStatsFunction · 0.85
attrMethod · 0.80
docMethod · 0.45
formatMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected