add global SENTINEL object

This commit is contained in:
Mike Fährmann
2020-05-19 21:47:18 +02:00
parent c8787647ed
commit 3201fe3521
5 changed files with 8 additions and 10 deletions

View File

@@ -139,7 +139,6 @@ def unset(path, key, *, conf=_config):
class apply():
"""Context Manager: apply a collection of key-value pairs"""
_sentinel = object()
def __init__(self, kvlist):
self.original = []
@@ -147,12 +146,12 @@ class apply():
def __enter__(self):
for path, key, value in self.kvlist:
self.original.append((path, key, get(path, key, self._sentinel)))
self.original.append((path, key, get(path, key, util.SENTINEL)))
set(path, key, value)
def __exit__(self, etype, value, traceback):
for path, key, value in self.original:
if value is self._sentinel:
if value is util.SENTINEL:
unset(path, key)
else:
set(path, key, value)