@@ -269,15 +269,15 @@ structure is::
269269 with-block
270270
271271The expression is evaluated, and it should result in an object that supports the
272- context management protocol (that is, has :meth: `__enter__ ` and :meth: `__exit__ `
272+ context management protocol (that is, has :meth: `~object. __enter__ ` and :meth: `~object. __exit__ `
273273methods).
274274
275- The object's :meth: `__enter__ ` is called before *with-block * is executed and
275+ The object's :meth: `~object. __enter__ ` is called before *with-block * is executed and
276276therefore can run set-up code. It also may return a value that is bound to the
277277name *variable *, if given. (Note carefully that *variable * is *not * assigned
278278the result of *expression *.)
279279
280- After execution of the *with-block * is finished, the object's :meth: `__exit__ `
280+ After execution of the *with-block * is finished, the object's :meth: `~object. __exit__ `
281281method is called, even if the block raised an exception, and can therefore run
282282clean-up code.
283283
@@ -296,7 +296,7 @@ part-way through the block.
296296.. note ::
297297
298298 In this case, *f * is the same object created by :func: `open `, because
299- :meth: `file .__enter__ ` returns *self *.
299+ :meth: `~object .__enter__ ` returns *self *.
300300
301301The :mod: `threading ` module's locks and condition variables also support the
302302':keyword: `with `' statement::
@@ -339,16 +339,16 @@ underlying implementation and should keep reading.
339339A high-level explanation of the context management protocol is:
340340
341341* The expression is evaluated and should result in an object called a "context
342- manager". The context manager must have :meth: `__enter__ ` and :meth: `__exit__ `
342+ manager". The context manager must have :meth: `~object. __enter__ ` and :meth: `~object. __exit__ `
343343 methods.
344344
345- * The context manager's :meth: `__enter__ ` method is called. The value returned
345+ * The context manager's :meth: `~object. __enter__ ` method is called. The value returned
346346 is assigned to *VAR *. If no ``as VAR `` clause is present, the value is simply
347347 discarded.
348348
349349* The code in *BLOCK * is executed.
350350
351- * If *BLOCK * raises an exception, the context manager's :meth: `__exit__ ` method
351+ * If *BLOCK * raises an exception, the context manager's :meth: `~object. __exit__ ` method
352352 is called with three arguments, the exception details (``type, value, traceback ``,
353353 the same values returned by :func: `sys.exc_info `, which can also be ``None ``
354354 if no exception occurred). The method's return value controls whether an exception
@@ -357,7 +357,7 @@ A high-level explanation of the context management protocol is:
357357 if you do the author of the code containing the ':keyword: `with `' statement will
358358 never realize anything went wrong.
359359
360- * If *BLOCK * didn't raise an exception, the :meth: `__exit__ ` method is still
360+ * If *BLOCK * didn't raise an exception, the :meth: `~object. __exit__ ` method is still
361361 called, but *type *, *value *, and *traceback * are all ``None ``.
362362
363363Let's think through an example. I won't present detailed code but will only
@@ -391,7 +391,7 @@ rolled back if there's an exception. Here's the basic interface for
391391 def rollback(self):
392392 "Rolls back current transaction"
393393
394- The :meth: `__enter__ ` method is pretty easy, having only to start a new
394+ The :meth: `~object. __enter__ ` method is pretty easy, having only to start a new
395395transaction. For this application the resulting cursor object would be a useful
396396result, so the method will return it. The user can then add ``as cursor `` to
397397their ':keyword: `with `' statement to bind the cursor to a variable name. ::
@@ -403,7 +403,7 @@ their ':keyword:`with`' statement to bind the cursor to a variable name. ::
403403 cursor = self.cursor()
404404 return cursor
405405
406- The :meth: `__exit__ ` method is the most complicated because it's where most of
406+ The :meth: `~object. __exit__ ` method is the most complicated because it's where most of
407407the work has to be done. The method has to check if an exception occurred. If
408408there was no exception, the transaction is committed. The transaction is rolled
409409back if there was an exception.
@@ -436,10 +436,10 @@ are useful when writing objects for use with the ':keyword:`with`' statement.
436436The decorator is called :func: `contextmanager `, and lets you write a single
437437generator function instead of defining a new class. The generator should yield
438438exactly one value. The code up to the :keyword: `yield ` will be executed as the
439- :meth: `__enter__ ` method, and the value yielded will be the method's return
439+ :meth: `~object. __enter__ ` method, and the value yielded will be the method's return
440440value that will get bound to the variable in the ':keyword: `with `' statement's
441441:keyword: `!as ` clause, if any. The code after the :keyword: `!yield ` will be
442- executed in the :meth: `__exit__ ` method. Any exception raised in the block will
442+ executed in the :meth: `~object. __exit__ ` method. Any exception raised in the block will
443443be raised by the :keyword: `!yield ` statement.
444444
445445Using this decorator, our database example from the previous section
@@ -1737,7 +1737,7 @@ Optimizations
17371737 (Contributed by Antoine Pitrou.) Memory usage is reduced
17381738 by using pymalloc for the Unicode string's data.
17391739
1740- * The ``with `` statement now stores the :meth: `__exit__ ` method on the stack,
1740+ * The ``with `` statement now stores the :meth: `~object. __exit__ ` method on the stack,
17411741 producing a small speedup. (Implemented by Jeffrey Yasskin.)
17421742
17431743* To reduce memory usage, the garbage collector will now clear internal
0 commit comments