| 166 | def stderr_log(msg:str): print(msg, end='', file=sys.stderr, flush=True) |
| 167 | |
| 168 | class Context(contextlib.ContextDecorator): |
| 169 | def __init__(self, **kwargs): self.kwargs = kwargs |
| 170 | def __enter__(self): |
| 171 | self.old_context:dict[str, Any] = {k: ContextVar._cache[k].value for k in self.kwargs} |
| 172 | for k,v in self.kwargs.items(): ContextVar._cache[k].value = v |
| 173 | def __exit__(self, *args): |
| 174 | for k,v in self.old_context.items(): ContextVar._cache[k].value = v |
| 175 | |
| 176 | class ContextVar(Generic[T]): |
| 177 | _cache: ClassVar[dict[str, ContextVar]] = {} |
no outgoing calls
searching dependent graphs…