Temporarily set configuration values within a context manager Parameters ---------- arg : mapping or None, optional A mapping of configuration key-value pairs to set. **kwargs : Additional key-value pairs to set. If ``arg`` is provided, values set in ``arg``
| 370 | |
| 371 | |
| 372 | class set: |
| 373 | """Temporarily set configuration values within a context manager |
| 374 | |
| 375 | Parameters |
| 376 | ---------- |
| 377 | arg : mapping or None, optional |
| 378 | A mapping of configuration key-value pairs to set. |
| 379 | **kwargs : |
| 380 | Additional key-value pairs to set. If ``arg`` is provided, values set |
| 381 | in ``arg`` will be applied before those in ``kwargs``. |
| 382 | Double-underscores (``__``) in keyword arguments will be replaced with |
| 383 | ``.``, allowing nested values to be easily set. |
| 384 | |
| 385 | Examples |
| 386 | -------- |
| 387 | >>> import dask |
| 388 | |
| 389 | Set ``'foo.bar'`` in a context, by providing a mapping. |
| 390 | |
| 391 | >>> with dask.config.set({'foo.bar': 123}): |
| 392 | ... pass |
| 393 | |
| 394 | Set ``'foo.bar'`` in a context, by providing a keyword argument. |
| 395 | |
| 396 | >>> with dask.config.set(foo__bar=123): |
| 397 | ... pass |
| 398 | |
| 399 | Set ``'foo.bar'`` globally. |
| 400 | |
| 401 | >>> dask.config.set(foo__bar=123) # doctest: +SKIP |
| 402 | |
| 403 | See Also |
| 404 | -------- |
| 405 | dask.config.get |
| 406 | """ |
| 407 | |
| 408 | config: dict |
| 409 | # [(op, path, value), ...] |
| 410 | _record: list[tuple[Literal["insert", "replace"], tuple[str, ...], Any]] |
| 411 | |
| 412 | def __init__( |
| 413 | self, |
| 414 | arg: Mapping | None = None, |
| 415 | config: dict | None = None, |
| 416 | lock: threading.Lock = config_lock, |
| 417 | **kwargs, |
| 418 | ): |
| 419 | if config is None: # Keep Sphinx autofunction documentation clean |
| 420 | config = global_config |
| 421 | |
| 422 | with lock: |
| 423 | self.config = config |
| 424 | self._record = [] |
| 425 | |
| 426 | if arg is not None: |
| 427 | for key, value in arg.items(): |
| 428 | key = check_deprecations(key) |
| 429 | self._assign(key.split("."), value, config) |
no outgoing calls