Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to declare a module deprecated in python

Tags:

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.

like image 826
saurbh Avatar asked May 07 '15 06:05

saurbh


People also ask

How do you write deprecated in Python?

use deprecation module to deprecate methods. deprecation is a library that enables automated deprecations. It offers the deprecated() decorator to wrap functions, providing proper warnings both in documentation and via Python's warnings system, as well as the deprecation.

What is a deprecated module?

Deprecated Modules is a module that will warn game masters whenever they use a module that they shouldn't be using anymore. This includes modules that have been integrated into core Foundry, modules that have been entirely replaced by other modules, and modules that have broken and are no longer being maintained.

What is deprecated mean in Python?

Usage of a module may be 'deprecated', which means that it may be removed from a future Python release.


1 Answers

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.

like image 116
abarnert Avatar answered Oct 14 '22 12:10

abarnert