settings_static.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. from __future__ import annotations
  2. from collections.abc import Iterable
  3. from typing import Any
  4. from wandb.sdk.wandb_settings import Settings
  5. class SettingsStatic(Settings):
  6. """A readonly object that wraps a protobuf Settings message.
  7. Implements the mapping protocol, so you can access settings as
  8. attributes or items.
  9. """
  10. def __init__(self, data: dict[str, Any]) -> None:
  11. super().__init__(**data)
  12. def __setattr__(self, name: str, value: object) -> None:
  13. raise AttributeError("Error: SettingsStatic is a readonly object")
  14. def __setitem__(self, key: str, val: object) -> None:
  15. raise AttributeError("Error: SettingsStatic is a readonly object")
  16. def keys(self) -> Iterable[str]:
  17. return self.__dict__.keys()
  18. def __getitem__(self, key: str) -> Any:
  19. return self.__dict__[key]
  20. def __getattr__(self, name: str) -> Any:
  21. try:
  22. return self.__dict__[name]
  23. except KeyError:
  24. raise AttributeError(f"SettingsStatic has no attribute {name}")
  25. def __str__(self) -> str:
  26. return str(self.__dict__)
  27. def __contains__(self, key: str) -> bool:
  28. return key in self.__dict__