From 6bfd864ff2a7d4903d485ee40094a1315da8221b Mon Sep 17 00:00:00 2001 From: Tommy Beadle Date: Mon, 13 Apr 2015 10:57:44 -0400 Subject: Fixed #24603 -- Allowed Context.update() to be used as a context manager. --- docs/ref/templates/api.txt | 15 +++++++++++++++ docs/releases/1.9.txt | 3 +++ 2 files changed, 18 insertions(+) (limited to 'docs') diff --git a/docs/ref/templates/api.txt b/docs/ref/templates/api.txt index 077330f6ce..5e56eff1d4 100644 --- a/docs/ref/templates/api.txt +++ b/docs/ref/templates/api.txt @@ -497,6 +497,21 @@ the stack instead of an empty one. >>> c['foo'] 'first level' +Like ``push()``, you can use ``update()`` as a context manager to ensure a +matching ``pop()`` is called. + + >>> c = Context() + >>> c['foo'] = 'first level' + >>> with c.update({'foo': 'second level'}): + ... c['foo'] + 'second level' + >>> c['foo'] + 'first level' + +.. versionadded:: 1.9 + + The ability to use ``update()`` as a context manager was added. + Using a ``Context`` as a stack comes in handy in :ref:`some custom template tags `. diff --git a/docs/releases/1.9.txt b/docs/releases/1.9.txt index 47c2bc98bc..25da6978ba 100644 --- a/docs/releases/1.9.txt +++ b/docs/releases/1.9.txt @@ -211,6 +211,9 @@ Templates * The :ttag:`firstof` template tag supports storing the output in a variable using 'as'. +* :meth:`Context.update() ` can now be used as + a context manager. + Requests and Responses ^^^^^^^^^^^^^^^^^^^^^^ -- cgit v1.3