Skip to content

Commit

Permalink
Improved reference_internal documentation (#5528)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
gentlegiantJGC authored Feb 20, 2025
1 parent b7c3300 commit 73825f3
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions docs/advanced/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,11 @@ The following table provides an overview of available policies:
| | it is no longer used. Warning: undefined behavior will ensue when the C++ |
| | side deletes an object that is still referenced and used by Python. |
+--------------------------------------------------+----------------------------------------------------------------------------+
| :enum:`return_value_policy::reference_internal` | Indicates that the lifetime of the return value is tied to the lifetime |
| | of a parent object, namely the implicit ``this``, or ``self`` argument of |
| | the called method or property. Internally, this policy works just like |
| :enum:`return_value_policy::reference_internal` | If the return value is an lvalue reference or a pointer, the parent object |
| | (the implicit ``this``, or ``self`` argument of the called method or |
| | property) is kept alive for at least the lifespan of the return value. |
| | **Otherwise this policy falls back to :enum:`return_value_policy::move` |
| | (see #5528).** Internally, this policy works just like |
| | :enum:`return_value_policy::reference` but additionally applies a |
| | ``keep_alive<0, 1>`` *call policy* (described in the next section) that |
| | prevents the parent object from being garbage collected as long as the |
Expand Down

0 comments on commit 73825f3

Please sign in to comment.