You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
All the calls to def_properties* eventually forwarded to def_property_static, and "extra" attributes are processed there, with process_attributes<Extra...>::init:
Just blindly pass "extra" attributes to the cpp_function constructor. I haven't yet analyzed possible side effects of this solution.
Workaround
keep_alive works when it is passed to the cpp_function constructor directly. If the maintainers choose not to update implementations, this (confusing) behavior should be documented IMO.
Required prerequisites
What version (or hash if on master) of pybind11 are you using?
2.10.4, but 8b48ff8 (the current master) still has the same problem.
Problem description
The problem
Passing
keep_alive
directly todef_property*
family is ignored. The flow:pybind11/include/pybind11/pybind11.h
Line 1750 in 8b48ff8
pybind11/include/pybind11/pybind11.h
Line 1766 in 8b48ff8
pybind11/include/pybind11/pybind11.h
Lines 1782 to 1783 in 8b48ff8
pybind11/include/pybind11/pybind11.h
Lines 1790 to 1794 in 8b48ff8
pybind11/include/pybind11/pybind11.h
Lines 1812 to 1813 in 8b48ff8
def_properties*
eventually forwarded todef_property_static
, and "extra" attributes are processed there, withprocess_attributes<Extra...>::init
:pybind11/include/pybind11/pybind11.h
Lines 1816 to 1848 in 8b48ff8
process_attribute<keep_alive<>>::init
:pybind11/include/pybind11/attr.h
Lines 644 to 650 in 8b48ff8
process_attribute<keep_alive<>>::init
is empty.pybind11/include/pybind11/attr.h
Lines 619 to 639 in 8b48ff8
Possible solution
Just blindly pass "extra" attributes to the
cpp_function
constructor. I haven't yet analyzed possible side effects of this solution.Workaround
keep_alive
works when it is passed to thecpp_function
constructor directly. If the maintainers choose not to update implementations, this (confusing) behavior should be documented IMO.Related issues
#4236, #4124, #2618, ...
Reproducible example code
No response
Is this a regression? Put the last known working version here if it is.
Not a regression
The text was updated successfully, but these errors were encountered: