MCPcopy Create free account
hub / github.com/MagicStack/contextvars / reset

Method reset

contextvars/__init__.py:120–138  ·  view source on GitHub ↗
(self, token)

Source from the content-addressed store, hash-verified

118 return Token(ctx, self, old_value)
119
120 def reset(self, token):
121 if token._used:
122 raise RuntimeError("Token has already been used once")
123
124 if token._var is not self:
125 raise ValueError(
126 "Token was created by a different ContextVar")
127
128 if token._context is not _get_context():
129 raise ValueError(
130 "Token was created in a different Context")
131
132 ctx = token._context
133 if token._old_value is Token.MISSING:
134 ctx._data = ctx._data.delete(token._var)
135 else:
136 ctx._data = ctx._data.set(token._var, token._old_value)
137
138 token._used = True
139
140 def __repr__(self):
141 r = '<ContextVar name={!r}'.format(self.name)

Callers 5

test_context_getset_1Method · 0.95
test_context_getset_2Method · 0.95
test_context_getset_4Method · 0.95
funMethod · 0.80

Calls 2

_get_contextFunction · 0.85
setMethod · 0.80

Tested by 5

test_context_getset_1Method · 0.76
test_context_getset_2Method · 0.76
test_context_getset_4Method · 0.76
funMethod · 0.64