13steinj
13steinj

Reputation: 467

Suppress warnings on import?

Assuming I write a python package that has to use the imp module, and my package is "TestModule" which is the following:

import imp
import pip
import sys

def update_and_reload(module, *args, **kwargs):
    pip.main(['install', module, '--upgrade', '--user'])
    return imp.reload(module)

When I do import TestModule in the terminal, I get a pending deprecation warning on imp. How would I make imp's warning not occur / filter out?

Upvotes: 1

Views: 6225

Answers (1)

Igor Pejic
Igor Pejic

Reputation: 3698

Well you could use the warning module:

import warnings

with warnings.catch_warnings():
    warnings.filterwarnings("ignore", category=DeprecationWarning)
    import imp
import pip
...    

Upvotes: 5

Related Questions