Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

_deprecate.py 2.0KB

1 year ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. from __future__ import annotations
  2. import warnings
  3. from . import __version__
  4. def deprecate(
  5. deprecated: str,
  6. when: int | None,
  7. replacement: str | None = None,
  8. *,
  9. action: str | None = None,
  10. plural: bool = False,
  11. ) -> None:
  12. """
  13. Deprecations helper.
  14. :param deprecated: Name of thing to be deprecated.
  15. :param when: Pillow major version to be removed in.
  16. :param replacement: Name of replacement.
  17. :param action: Instead of "replacement", give a custom call to action
  18. e.g. "Upgrade to new thing".
  19. :param plural: if the deprecated thing is plural, needing "are" instead of "is".
  20. Usually of the form:
  21. "[deprecated] is deprecated and will be removed in Pillow [when] (yyyy-mm-dd).
  22. Use [replacement] instead."
  23. You can leave out the replacement sentence:
  24. "[deprecated] is deprecated and will be removed in Pillow [when] (yyyy-mm-dd)"
  25. Or with another call to action:
  26. "[deprecated] is deprecated and will be removed in Pillow [when] (yyyy-mm-dd).
  27. [action]."
  28. """
  29. is_ = "are" if plural else "is"
  30. if when is None:
  31. removed = "a future version"
  32. elif when <= int(__version__.split(".")[0]):
  33. msg = f"{deprecated} {is_} deprecated and should be removed."
  34. raise RuntimeError(msg)
  35. elif when == 10:
  36. removed = "Pillow 10 (2023-07-01)"
  37. elif when == 11:
  38. removed = "Pillow 11 (2024-10-15)"
  39. else:
  40. msg = f"Unknown removal version: {when}. Update {__name__}?"
  41. raise ValueError(msg)
  42. if replacement and action:
  43. msg = "Use only one of 'replacement' and 'action'"
  44. raise ValueError(msg)
  45. if replacement:
  46. action = f". Use {replacement} instead."
  47. elif action:
  48. action = f". {action.rstrip('.')}."
  49. else:
  50. action = ""
  51. warnings.warn(
  52. f"{deprecated} {is_} deprecated and will be removed in {removed}{action}",
  53. DeprecationWarning,
  54. stacklevel=3,
  55. )