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

Function add_object

include/pybind11/pybind11.h:1690–1698  ·  view source on GitHub ↗

\rst Adds an object to the module using the given name. Throws if an object with the given name already exists. ``overwrite`` should almost always be false: attempting to overwrite objects that pybind11 has established will, in most cases, break things. \endrst */

Source from the content-addressed store, hash-verified

1688 has established will, in most cases, break things.
1689 \endrst */
1690 PYBIND11_NOINLINE void add_object(const char *name, handle obj, bool overwrite = false) {
1691 if (!overwrite && hasattr(*this, name)) {
1692 pybind11_fail(
1693 "Error during initialization: multiple incompatible definitions with name \""
1694 + std::string(name) + "\"");
1695 }
1696
1697 PyModule_AddObject(ptr(), name, obj.inc_ref().ptr() /* steals a reference */);
1698 }
1699
1700 // DEPRECATED (since PR #5688): Use PyModuleDef directly instead.
1701 using module_def = PyModuleDef;

Callers 1

pybind11.hFile · 0.85

Calls 4

hasattrFunction · 0.85
ptrFunction · 0.85
ptrMethod · 0.80
inc_refMethod · 0.80

Tested by

no test coverage detected