Commits

Anonymous committed 2bd660d

New helper ``deprecate()``.

Comments (0)

Files changed (3)

docs/modules/misc.rst

 .. autofunction:: no(seq[, pred])
 .. autofunction:: count_true(seq[, pred])
 .. autofunction:: convert_or_none
+.. autofunction:: deprecate
 
 .. autoclass:: DeclarativeException
     :members:

docs/whats_new.rst

 
 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.
 
 webhelpers.paginate
 +++++++++++++++++++

webhelpers/misc.py

 
 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
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.