Skip to content Skip to sidebar Skip to footer

Unable To Suppress Deprecation Warnings

In my Django application, when I import one third party library, I get this warning in the console: the imp module is deprecated in favour of importlib; see the module's documenta

Solution 1:

There are a couple of issues with the code you've tried. If you want to filter PendingDeprecationWarning, then you should use PendingDeprecationWarning in your code. Your code is using DeprecationWarning and RemovedInDjango110Warning, which are different warnings. Secondly, the fxn() function in the docs is an example function that creates a warning. It doesn't make sense to include it in your code.

You can either filter all pending deprecation warnings

import warnings
warnings.simplefilter("ignore", category=PendingDeprecationWarning)

However this might hide pending deprecations in your own code that you should fix. A better approach would be to use a context manager, to filter out warnings when importing the third-party lib.

with warnings.catch_warnings():
    warnings.simplefilter("ignore", category=PendingDeprecationWarning)
    from third_party_lib import some_module

Post a Comment for "Unable To Suppress Deprecation Warnings"