Skip to content

[FEAT] docs: keep_alive should have more nuanced explanation for constructors? #2978

@EricCousineau-TRI

Description

@EricCousineau-TRI

At present, pybind11 docs for keep alive are as follows:
https://pybind11.readthedocs.io/en/stable/advanced/functions.html?highlight=keep_alive#keep-alive
https://github.com/pybind/pybind11/blob/v2.6.2/docs/advanced/functions.rst#keep-alive

Argument indices start at one, while zero refers to the return value. For methods, index 1 refers to the implicit this pointer, while regular arguments begin at index 2.

However, it doesn't cover cases like constructors, either via vanilla py::init(), or factory-style constructors, as indicated here:
https://pybind11.readthedocs.io/en/stable/advanced/classes.html#custom-constructors

I think we (Drake devs) operate under the assumption that a constructor functions as a method, and thus keep_alive<1, 2>() would be something like "Keep alive: self keeps first arg alive", but I'm not sure upon reinspection.

Motivation: RobotLocomotion/drake#14925 (review)

\cc @hongkai-dai

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions