Anonymous committed 2bd660d

New helper ``deprecate()``.

Comments (0)

Files changed (3)


 .. autofunction:: no(seq[, pred])
 .. autofunction:: count_true(seq[, pred])
 .. autofunction:: convert_or_none
+.. autofunction:: deprecate
 .. autoclass:: DeclarativeException
 New helpers to flatten nested lists and tuples, and to
 gather all the subclasses of a specified class. There's an exception
-``OverwriteError``, and a ``DeclarativeException`` class for making your own
-exceptions with constant messages.
+``OverwriteError``, a ``DeclarativeException`` class for making your own
+exceptions with constant messages, and a ``deprecate`` function.
 import itertools
 import types
+import warnings
 def all(seq, pred=None):
     """Is ``pred(elm)`` true for all elements?
         Exception.__init__(self, message)
         self.filename = filename
+def deprecate(message, pending=False, stacklevel=2):
+    """Issue a deprecation warning.
+    ``message``: the deprecation message.
+    ``pending``: if true, use ``PendingDeprecationWarning``. If false (default), 
+    use ``DeprecationWarning``. Python displays deprecations and ignores
+    pending deprecations by default.
+    ``stacklevel``: passed to ``warnings.warn``. The default level 2 makes the
+    traceback end at the caller's level. Higher numbers make it end at higher
+    levels.
+    """
+    category = pending and PendingDeprecationWarning or DeprecationWarning
+    warnings.warn(message, category, stacklevel)
 if __name__ == "__main__":
     import doctest