betty.warnings - Betty documentation

Hide navigation sidebar
Hide table of contents sidebar
Skip to content
Back to top
Toggle table of contents sidebar

# Source code for betty.warnings

    """
    Provide utilities for raising warnings.
    """

    import warnings

    import typing_extensions

    class BettyDeprecationWarning(DeprecationWarning):
        """
        Raised for deprecated Betty functionality.
        """

        pass  # pragma: no cover

    def deprecate(message: str, stacklevel: int = 1):
        """
        Raise a Betty deprecation warning.
        """
        warnings.warn(message, category=BettyDeprecationWarning, stacklevel=stacklevel + 1)

    class deprecated(typing_extensions.deprecated):
        """
        Decorate a class, function, or overload to indicate that it is depreated.

        This is identical to :py:class:`warnings.deprecated`, but raises a Betty
        deprecation warning.
        """

        def __init__(self, message: str, stacklevel: int = 1):
            super().__init__(
                message, category=BettyDeprecationWarning, stacklevel=stacklevel
            )