@@ -25,11 +25,11 @@ Executing code in a Python `with` statement
2525===========================================
2626
2727Where in C++, the scope of local variables and their destructor is used to manage
28- resources in the RAII idiom, Python has a `with ` statement and context managers
29- for such situations. At the start and end of the `with ` statement, the context
30- manager's `__enter__ ` and `__exit__ ` methods are called, respectively. To more
28+ resources in the RAII idiom, Python has a `` with ` ` statement and context managers
29+ for such situations. At the start and end of the `` with ` ` statement, the context
30+ manager's `` __enter__ `` and `` __exit__ ` ` methods are called, respectively. To more
3131easily use context managers in a C++ context, pybind11 provides a utility function
32- `` py::with `` , that matches the semantics of a Python `with `-statement (see
32+ `py::with <with> ` , that matches the semantics of a Python `` with ` `-statement (see
3333`PEP 343 <https://www.python.org/dev/peps/pep-0343/ >`_):
3434
3535.. code-block :: cpp
@@ -53,13 +53,13 @@ This code snippet corresponds to the following in Python:
5353 f.write(" \n " )
5454
5555 The `py::object ` parameter of the lambda function can be omitted if the object resulting
56- from the context manager (i.e., the `as VAR ` part in the `with ` statement) is not of use.
56+ from the context manager (i.e., the `` as VAR `` part in the `` with ` ` statement) is not of use.
5757
58- Optionally, an extra `py::with_exception_policy ` argument can be passed to ` py::with `.
59- If the value `py::with_exception_policy::translate ` is selected, pybind11 will try to
60- translate any C++ exception inside the `with ` statement and pass the Python exception
61- as argument into the `__exit__ ` method of the context manager (cfr. PEP 343). If
62- ` py::with_exception_policy::translate ` is passed and an exception gets thrown, pybind11
58+ Optionally, an extra `py::with_exception_policy <with_exception_policy> ` argument can be
59+ passed to ` py::with <with> `. If the value `` py::with_exception_policy::translate `` is selected,
60+ pybind11 will try to translate any C++ exception inside the `` with `` statement and pass the
61+ Python exception as argument into the `` __exit__ `` method of the context manager (cfr. PEP 343).
62+ If `` py::with_exception_policy::translate ` ` is passed and an exception gets thrown, pybind11
6363will not try to translate it, `__exit__ ` will be called as if no exception was thrown,
6464and the original exception will be cascaded down to the caller.
6565
0 commit comments