1
0
mirror of https://github.com/ARM-software/devlib.git synced 2025-09-23 04:11:54 +01:00

target: Use Target._xfer_cache_file() context manager

Use the context manager to simplify the file transfer cache management.

Also introduce devlib.utils.misc.nullcontext() mirroring the behavior of
contextlib.nullcontext().
This commit is contained in:
douglas-raillard-arm
2020-06-17 12:59:10 +01:00
committed by Marc Bonnici
parent 24e6de67ae
commit f23fbd22b6
2 changed files with 37 additions and 19 deletions

View File

@@ -737,6 +737,23 @@ def batch_contextmanager(f, kwargs_list):
stack.enter_context(f(**kwargs))
yield
@contextmanager
def nullcontext(enter_result=None):
"""
Backport of Python 3.7 ``contextlib.nullcontext``
This context manager does nothing, so it can be used as a default
placeholder for code that needs to select at runtime what context manager
to use.
:param enter_result: Object that will be bound to the target of the with
statement, or `None` if nothing is specified.
:type enter_result: object
"""
yield enter_result
class tls_property:
"""
Use it like `property` decorator, but the result will be memoized per