Greg wished for:

    ... compiler recognition of "@deprecated" in doc comments.

Michael Chermside suggested:

    ===== code =====
    import warnings

    def deprecated(func):
        """This is a decorator which can be used to mark functions
        as deprecated. It will result in a warning being emmitted
        when the function is used."""
        def newFunc(*args, **kwargs):
            warnings.warn("Call to deprecated function.")
            return func(*args, **kwargs)
        return newFunc

    ===== example =====
...
    UserWarning: Call to deprecated function.

I agree that it should go in the cookbook, but I think you should
set the category to a DeprecationWarning and give the offending
function's name.  (Whether to worry about suppression of calls 
to *other* deprecated functions -- I think is out of scope for a recipe.)

    def newFunc(*args, **kwargs):
        warnings.warn("Call to deprecated function %s" % func.__name__,
                      category=DeprecationWarning)
        return func(*args, **kwargs)

-jJ
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to