Patchwork [2,of,4] util: enhance `nullcontextmanager` to be able to return __enter__ result

login
register
mail settings
Submitter Manuel Jacob
Date July 17, 2020, 2:38 a.m.
Message ID <90b4881b969cb70d68c8.1594953528@tmp>
Download mbox | patch
Permalink /patch/46768/
State Accepted
Headers show

Comments

Manuel Jacob - July 17, 2020, 2:38 a.m.
# HG changeset patch
# User Manuel Jacob <me@manueljacob.de>
# Date 1594936144 -7200
#      Thu Jul 16 23:49:04 2020 +0200
# Node ID 90b4881b969cb70d68c8b5248e784987d4c70de4
# Parent  217660a6547cb5db3a53456998032cbfcd069967
# EXP-Topic stdio-broken_pipe
util: enhance `nullcontextmanager` to be able to return __enter__ result

This makes its functionality and signature equivalent to Python 3.7’s
contextlib.nullcontext().

Patch

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -1381,8 +1381,8 @@ 
 
 
 @contextlib.contextmanager
-def nullcontextmanager():
-    yield
+def nullcontextmanager(enter_result=None):
+    yield enter_result
 
 
 class _lrucachenode(object):