sentinel.py 642 B

123456789101112131415161718192021222324
  1. """Sentinel class for constants with useful reprs"""
  2. # Copyright (c) IPython Development Team.
  3. # Distributed under the terms of the Modified BSD License.
  4. from __future__ import annotations
  5. import typing as t
  6. class Sentinel:
  7. def __init__(self, name: str, module: t.Any, docstring: str | None = None) -> None:
  8. self.name = name
  9. self.module = module
  10. if docstring:
  11. self.__doc__ = docstring
  12. def __repr__(self) -> str:
  13. return str(self.module) + "." + self.name
  14. def __copy__(self) -> Sentinel:
  15. return self
  16. def __deepcopy__(self, memo: t.Any) -> Sentinel:
  17. return self