-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Description
DeprecationWarning and PendingDeprecationWarning are invisible by default. The rationale for this is that they are only useful to people who are writing code, so they should not be shown to end-users who are merely running code.
If someone is typing stuff into the interactive REPL or a notebook, though, and the code they type uses some deprecated functionality, then we should actually show them this warning. We know that the author is sitting right there. And they're probably going to take whatever they tested interactively and move it into a more permanent form and ugh.
This problem is particularly acute for packages that are primarily used through the interactive prompt, like numpy. I'm really tired of getting bugs like this: numpy/numpy#5919
The solution is simple: when entering interactive mode, IPython should do something like:
warnings.filterwarnings("default", category=DeprecationWarning, module="__main__")
warnings.filterwarnings("default", category=PendingDeprecationWarning, module="__main__")
This means "for any DeprecationWarning or PendingDeprecation warning which is caused by code running in the module with name "__main__", use the "default" handler (which means: display once per line of code that triggered it). (Confusingly, the default handler for these warning messages is not "default", but "ignore". So overriding the default with "default" produces a non-default outcome.)