How can I increase depreciation in Python 2.7?

I am trying to mark a function as deprecated so that the script call is executed before it completes normally, but falls into the verification of the PyCharm static code. (There are several other questions about these failure warnings, but I think they preceded Python 2.6 when I believe that class-based exceptions were introduced.)

Here is what I have:

class Deprecated(DeprecationWarning): pass def save_plot_and_insert(filename, worksheet, row, col): """ Deprecated. Docstring ...<snip> """ raise Deprecated() # Active lines of # the function here # ... 

I understand that legacy warnings should allow code to run, but this code example actually stops when the function is called. When I remove the β€œraise” from the function body, the code is executed, but PyCharm does not mark the function call as deprecated.

What is the Pythonic method (2.7.x) for marking functions as deprecated?

+7
pycharm
source share
1 answer

You should not raise DeprecationWarning (or a subclass) because you are still raising the actual exception.

Use warnings.warn :

 import warnings warnings.warn("deprecated", DeprecationWarning) 

https://docs.python.org/2/library/warnings.html#warnings.warn

+14
source share

All Articles