comparison cutils/util/cm.py @ 115:e15b3d1ff0d9

New subpackage with a "contextlib.nullcontext" for older Python versions
author Franz Glasner <fzglas.hg@dom66.de>
date Sun, 29 Dec 2024 15:31:38 +0100
parents
children dfe7bb0579e2
comparison
equal deleted inserted replaced
114:9e61c5cf76a2 115:e15b3d1ff0d9
1 # -*- coding: utf-8 -*-
2 # :-
3 # :Copyright: (c) 2020-2024 Franz Glasner
4 # :License: BSD-3-Clause
5 # :-
6 r"""Context manager extensions and compatibility.
7
8 """
9
10 __all__ = ["nullcontext"]
11
12
13 try:
14 from contextlib import nullcontext
15 except ImportError:
16 class nullcontext(object):
17
18 """Compatibility implementation for systems that are missing yet
19 a standard :class:`contextlib.nullcontext`.
20
21 """
22
23 __slots__ = ("thing", )
24
25 def __init__(self, thing=None):
26 self.thing = thing
27
28 def __enter__(self):
29 return self.thing
30
31 def __exit__(self, *args, **kwds):
32 pass