Skip to content
Advertisement

Python: Issue Deprecation warning when importing a function

in a file B.py I have a function hello(). The location is deprecated and I moved it to A.py.

Currently I do:

JavaScript

but this issues the warning when the function is called. I want to issue the warning when the function is imported. Is it possible to issue a warning if a function is imported like this:

JavaScript

B.py also has some other functions, which are not deprecated.

Advertisement

Answer

Using a decorator on the function should work, the warning will be shown when the function is imported or called. Please double check that the function is not executed on import (it shouldn’t be).

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement