pycharm - How do I raise DeprecationWarnings in Python 2.7? -


i'm trying mark function deprecated script calling runs normal completion, gets caught pycharm's static code inspections. (there other questions on deprecation warnings, think predate python 2.6, when believe class-based exceptions introduced.)

here's have:

class deprecated(deprecationwarning):     pass  def save_plot_and_insert(filename, worksheet, row, col):     """     deprecated. docstring ...<snip>     """      raise deprecated()      # active lines of     # function here     # ... 

my understanding deprecated warnings should allow code run, code sample halts when function called. when remove "raise" body of function, code runs, pycharm doesn't mark function call deprecated.

what pythonic (2.7.x) way of marking functions deprecated?

you shouldn't raise deprecationwarning (or subclass) because still raising actual exception.

instead use warnings.warn:

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

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


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -