How to declare a module deprecated in python

前端 未结 1 1749
情书的邮戳
情书的邮戳 2021-01-07 18:48

How to declare a module deprecated in python?

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

相关标签:
1条回答
  • 2021-01-07 19:20

    You want to warn with a DeprecationWarning.

    Exactly how you call it doesn't matter that much, but the stdlib has a standard pattern for deprecated 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 the 2.7 sets source for an example.

    0 讨论(0)
提交回复
热议问题