_compatibility.py 1.0 KB

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