[Python-ideas] Show deprecation warnings in the interactive interpreter
Terry Reedy
tjreedy at udel.edu
Thu Feb 26 02:58:24 CET 2015
On 2/25/2015 4:35 PM, Nick Coghlan wrote:
> Setting the action to "always" and filtering on the main module should
> do the trick:
>
> >>> import warnings
> >>> warnings.filterwarnings("always", module="__main__")
Changing interactive-mode python is irrelevant to gui environments
running on batch-mode python, except for adding another requirement for
simulating interactive python and its command prompt. Idle starts
idlelib/PyShell.py in one process (the Idle process) and (in default
mode) idlelib/run.py in a second process (the User process) and makes a
bidirectional connection. The Idle process compiles user code with
compile(codestring, ...) and sends the code object to the User process,
which executes it with exec(usercode, namespace).
Both processes already import warnings. If I add the line above to
run.py, I get
>>> warnings.warn("Deprecated", DeprecationWarning)
Warning (from warnings module):
File "__main__", line 1
DeprecationWarning: Deprecated
(on stderr) instead of nothing. I presume this should be sufficient for
runtime warnings, but are there any raised during compilation (like
SyntaxWarnings, or Py3kWarnings in 2.7)? I see nothing in the compile()
doc about turning warnings on or off.
--
Terry Jan Reedy
More information about the Python-ideas
mailing list