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:
parent
ff2268b715
commit
ef9384d161
@ -748,8 +748,7 @@ def batch_contextmanager(f, kwargs_list):
|
|||||||
yield
|
yield
|
||||||
|
|
||||||
|
|
||||||
@contextmanager
|
class nullcontext:
|
||||||
def nullcontext(enter_result=None):
|
|
||||||
"""
|
"""
|
||||||
Backport of Python 3.7 ``contextlib.nullcontext``
|
Backport of Python 3.7 ``contextlib.nullcontext``
|
||||||
|
|
||||||
@ -761,7 +760,20 @@ def nullcontext(enter_result=None):
|
|||||||
statement, or `None` if nothing is specified.
|
statement, or `None` if nothing is specified.
|
||||||
:type enter_result: object
|
: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:
|
class tls_property:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user