How to deprecate a module in python

How to deprecate a module in python?

I want an alert to be printed whenever any particular module is imported or any of its functions are called.

+3


source to share


1 answer


Do you want warn

with DeprecationWarning

.

Exactly what you call it, it's not that important, but stdlib has a standard template for legacy modules, like this:



# doc string, top-level comments, imports, __all__ =

import warnings
warnings.warn("the spam module is deprecated", DeprecationWarning,
              stacklevel=2)

# normal module code

      

See source 2.7sets

.

+6


source







All Articles