1
0
mirror of https://github.com/ARM-software/devlib.git synced 2025-01-31 02:00:45 +00:00

utils.misc: Make nullcontext work with asyncio

Implement __aenter__ and __aexit__ on nullcontext so it can be used as
an asynchronous context manager.
This commit is contained in:
Douglas Raillard 2021-11-15 15:18:20 +00:00 committed by Marc Bonnici
parent ff2268b715
commit ef9384d161

View File

@ -748,8 +748,7 @@ def batch_contextmanager(f, kwargs_list):
yield
@contextmanager
def nullcontext(enter_result=None):
class nullcontext:
"""
Backport of Python 3.7 ``contextlib.nullcontext``
@ -761,7 +760,20 @@ def nullcontext(enter_result=None):
statement, or `None` if nothing is specified.
:type enter_result: object
"""
yield enter_result
def __init__(self, enter_result=None):
self.enter_result = enter_result
def __enter__(self):
return self.enter_result
async def __aenter__(self):
return self.enter_result
def __exit__(*_):
return
async def __aexit__(*_):
return
class tls_property: