This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author njs
Recipients ezio.melotti, martin.panter, ncoghlan, njs, serhiy.storchaka, takluyver, terry.reedy
Date 2015-05-28.08:14:16
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
There isn't really any magic in how warnings work. Basically someone calls warnings.warn(...), which is a regular Python function, and it gathers up some information about the specific warning message and calling context, checks a global variable ("warnings.filters") to decide how this message in this context should be handled, and then either does nothing, prints something to stderr, or raises an exception.

There are lots of warnings that are printed by default, and I'm sure IDLE is handling them fine already. It's just (Pending)DeprecationWarnings in particular that have an entry stuck into warnings.filters saying "please ignore these" (unless it gets overridden by something else).

So you just need to make sure that a filter is added to warnings.filters that says to treat DeprecationWarnings generated by the __main__ module using the "default" action. ("default" is the name of a specific way of handling warnings; for most types of warnings, the default handler is the one named "default", but for DeprecationWarning, the default handler is the one named "ignore". Obvious, right?)

So you just need to make sure to run the following line of code somewhere in the user process:

warnings.filterwarnings("default", category=DeprecationWarning, module="__main__")

Adjust as necessary if (a) you want to apply similar handling to PendingDeprecationWarning, (b) your user namespace has some value of __name__ that is different from "__main__".

Then to test, you can just type

warnings.warn("foo", DeprecationWarning)

at the prompt, and it should be printed.

Note that because the warnings module tries to suppress duplicate warnings (which is good), and it has a bug where it can't tell the difference between different lines of code at the REPL (this is bad -- see , and there should probably be a python bug too but I haven't gotten around to filing it), then the *second* time you run that line of code in the same REPL, nothing will be printed. So the moral is just, when testing this, make sure you use a different warning message each time, or you'll get very confused.
Date User Action Args
2015-05-28 08:14:16njssetrecipients: + njs, terry.reedy, ncoghlan, ezio.melotti, takluyver, martin.panter, serhiy.storchaka
2015-05-28 08:14:16njssetmessageid: <>
2015-05-28 08:14:16njslinkissue24294 messages
2015-05-28 08:14:16njscreate