(**new_env: str | Omit)
| 163 | |
| 164 | @contextlib.contextmanager |
| 165 | def update_env(**new_env: str | Omit) -> Iterator[None]: |
| 166 | old = os.environ.copy() |
| 167 | |
| 168 | try: |
| 169 | for name, value in new_env.items(): |
| 170 | if isinstance(value, Omit): |
| 171 | os.environ.pop(name, None) |
| 172 | else: |
| 173 | os.environ[name] = value |
| 174 | |
| 175 | yield None |
| 176 | finally: |
| 177 | os.environ.clear() |
| 178 | os.environ.update(old) |
| 179 | |
| 180 | |
| 181 | _T = TypeVar("_T") |