Temporarily set environment variables inside the context manager and fully restore previous environment afterwards
(**kwargs: str)
| 220 | |
| 221 | @contextmanager |
| 222 | def set_environ(**kwargs: str) -> Iterator[None]: |
| 223 | """Temporarily set environment variables inside the context manager and |
| 224 | fully restore previous environment afterwards |
| 225 | """ |
| 226 | |
| 227 | original_env = {k: os.environ.get(k) for k in kwargs} |
| 228 | os.environ.update(kwargs) |
| 229 | try: |
| 230 | yield |
| 231 | finally: |
| 232 | for k, v in original_env.items(): |
| 233 | if v is None: |
| 234 | del os.environ[k] |
| 235 | else: |
| 236 | os.environ[k] = v |
| 237 | |
| 238 | |
| 239 | def walk_callable(node: ast.AST) -> Iterable[ast.AST]: |