This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author hniksic
Recipients hniksic
Date 2010-10-08.11:13:43
SpamBayes Score 7.641492e-05
Marked as misclassified No
Message-id <>
I find that I frequently need the "null" (no-op) context manager.  For example, in code such as:

with transaction or contextlib.null():

Since there is no easy expression to create a null context manager, we must resort to workarounds, such as:

if transaction:
    with transaction:
        ... code ...
    ... duplicated code ...

(with the usual options of moving the duplicated code to a function—but still.)

Or by creating ad-hoc null context managers with the help of contextlib.contextmanager:

if transaction is None:
    transaction = contextlib.contextmanager(lambda: iter([None])()
with transaction:

Adding a "null" context manager would be both practical and elegant.  I have attached a patch for
Date User Action Args
2010-10-08 11:13:46hniksicsetrecipients: + hniksic
2010-10-08 11:13:46hniksicsetmessageid: <>
2010-10-08 11:13:44hniksiclinkissue10049 messages
2010-10-08 11:13:43hniksiccreate