Skip to content

Commit 73825f3

Browse files
Improved reference_internal documentation (#5528)
* Improved reference_internal documentation Improved the wording to make it easier to understand and added a note about the policy falling back to move if the return value is not an lvalue reference or pointer. * Added bold and ticket number
1 parent b7c3300 commit 73825f3

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

docs/advanced/functions.rst

+5-3
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,11 @@ The following table provides an overview of available policies:
8181
| | it is no longer used. Warning: undefined behavior will ensue when the C++ |
8282
| | side deletes an object that is still referenced and used by Python. |
8383
+--------------------------------------------------+----------------------------------------------------------------------------+
84-
| :enum:`return_value_policy::reference_internal` | Indicates that the lifetime of the return value is tied to the lifetime |
85-
| | of a parent object, namely the implicit ``this``, or ``self`` argument of |
86-
| | the called method or property. Internally, this policy works just like |
84+
| :enum:`return_value_policy::reference_internal` | If the return value is an lvalue reference or a pointer, the parent object |
85+
| | (the implicit ``this``, or ``self`` argument of the called method or |
86+
| | property) is kept alive for at least the lifespan of the return value. |
87+
| | **Otherwise this policy falls back to :enum:`return_value_policy::move` |
88+
| | (see #5528).** Internally, this policy works just like |
8789
| | :enum:`return_value_policy::reference` but additionally applies a |
8890
| | ``keep_alive<0, 1>`` *call policy* (described in the next section) that |
8991
| | prevents the parent object from being garbage collected as long as the |

0 commit comments

Comments
 (0)