Python: how to show DeprecationWarnings only when my code fires

Is there a way to show DeprecationWarnings if and only if they were called by my code (i.e. if I can fix them)?

For example, if the foo module is deprecated (and calls warnings.warn upon import), I would like to see a warning if the import call is in one of my "files" (identified, for example, by its path), but I would like it to be hidden if my code imports bar (also out of my control) which then imports foo .

The warnings.filterwarnings function takes a module parameter, but as far as I can tell, this maps to the module that generated the warning. I believe that I am interested in the module, which is one stack of frames above.

+5
source share

Source: https://habr.com/ru/post/1244908/


All Articles