[New-bugs-announce] [issue31975] Add a default filter for DeprecationWarning in __main__

Nick Coghlan report at bugs.python.org
Tue Nov 7 21:55:09 EST 2017


New submission from Nick Coghlan <ncoghlan at gmail.com>:

As per the post at https://mail.python.org/pipermail/python-dev/2017-November/150366.html, this is an RFE to cover adding a new warning filter to the default set:

    once::DeprecationWarning:__main__

This means that all deprecation warnings triggered directly by code in __main__ will start being reported again, while deprecation warnings triggered by imported modules will continue to be ignored by default.

Thus the following will start emitting DeprecationWarning by default again (as they did in 2.6 and earlier):

- experiments at the REPL
- directly executed scripts
- modules executed with the -m switch
- pkg.__main__ submodules executed with the -m switch
- __main__.py files in executed directories and zip archives

However, any code *imported* from these will not trigger warnings.

This means that the following still won't trigger any warnings by default:

- modules imported & functions called from entry point wrapper scripts
- modules imported & functions called from pkg.__main__ submodules
- modules imported & functions called from __main__.py files

The intent behind the change is that it should be much harder for developers and educators to miss seeing a deprecation warning at least once for a deprecated API, while still silencing deprecation warnings by default for deployed Python applications.

----------
messages: 305801
nosy: alex, gvanrossum, ncoghlan
priority: normal
severity: normal
stage: needs patch
status: open
title: Add a default filter for DeprecationWarning in __main__
type: enhancement
versions: Python 3.7

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue31975>
_______________________________________


More information about the New-bugs-announce mailing list