_compatibility.py 1000 B

12345678910111213141516171819202122232425262728293031323334
  1. from typing import Any, Dict
  2. import textwrap
  3. _BACK_COMPAT_OBJECTS : Dict[Any, None] = {}
  4. _MARKED_WITH_COMATIBLITY : Dict[Any, None] = {}
  5. def compatibility(is_backward_compatible : bool):
  6. if is_backward_compatible:
  7. def mark_back_compat(fn):
  8. docstring = textwrap.dedent(getattr(fn, '__doc__', None) or '')
  9. docstring += """
  10. .. note::
  11. Backwards-compatibility for this API is guaranteed.
  12. """
  13. fn.__doc__ = docstring
  14. _BACK_COMPAT_OBJECTS.setdefault(fn)
  15. _MARKED_WITH_COMATIBLITY.setdefault(fn)
  16. return fn
  17. return mark_back_compat
  18. else:
  19. def mark_not_back_compat(fn):
  20. docstring = textwrap.dedent(getattr(fn, '__doc__', None) or '')
  21. docstring += """
  22. .. warning::
  23. This API is experimental and is *NOT* backward-compatible.
  24. """
  25. fn.__doc__ = docstring
  26. _MARKED_WITH_COMATIBLITY.setdefault(fn)
  27. return fn
  28. return mark_not_back_compat