2017-11-12 10:24 GMT+01:00 Nick Coghlan <ncogh...@gmail.com>:
> I've written a short(ish) PEP for the proposal to change the default
> warnings filters to show DeprecationWarning in __main__:
> https://www.python.org/dev/peps/pep-0565/

I understand the rationale of the PEP, but I dislike the proposed
implementation.

End users will start to get warnings that they don't understand and
cannot fix, so these warnings would just be annoying.

For scripts written to only be run once and then deleted, again, these
warnings are just annoying since the script is going to be deleted
anyway.

It's like the annoying ResourceWarning (in debug mode) when I write
open(filename).read() in the REPL. I know that it's bad, but the code
will only be run once and lost when I quit the REPL, so who cares?
(not me, stop bothering me with good programming practices, I do know
them, let me write crappy code!) On the REPL case, I have no strong
opinion.

For developers who want to see warnings, the warnings are not shown
for applications using an entry point and any code base larger than a
single file (warnings outside the __main__ module).

--

In practice, I'm running tests with python -Wd (to see ResourceWarning
in my case), and I'm happy with that :-) If tests pass with -Wd,
you're good.

This is why I implemented a new "development mode", python3 -X dev, in
Python 3.7 which "shows all warnings except of BytesWarning". (This
mode is already mentioned in Nick's PEP.)
https://docs.python.org/dev/using/cmdline.html#id5

My advice is to always run your tests with -X dev. If they pass with
-X dev, you are good.

I'm not even sure that developers should use -X dev to test their code
manually. I see it as a "cheap linter". I don't want to run a linter
each time I run Python.

The "-X dev" option is smarter than -Wd: it adds the default filter
*at the end*, to respect -b and -bb options for the BytesWarning.

Release build:

$ ./python -c 'import pprint, warnings; pprint.pprint(warnings.filters)'
[('ignore', None, <class 'DeprecationWarning'>, None, 0),
 ('ignore', None, <class 'PendingDeprecationWarning'>, None, 0),
 ('ignore', None, <class 'ImportWarning'>, None, 0),
 ('ignore', None, <class 'BytesWarning'>, None, 0),
 ('ignore', None, <class 'ResourceWarning'>, None, 0)]

-Wd on the release build adds a filter at the start:

$ ./release.python -Wd -c 'import pprint, warnings;
pprint.pprint(warnings.filters)'
[('default', None, <class 'Warning'>, None, 0),   <~~~ HERE
 ('ignore', None, <class 'DeprecationWarning'>, None, 0),
 ('ignore', None, <class 'PendingDeprecationWarning'>, None, 0),
 ('ignore', None, <class 'ImportWarning'>, None, 0),
 ('ignore', None, <class 'BytesWarning'>, None, 0),
 ('ignore', None, <class 'ResourceWarning'>, None, 0)]

Debug build:

$ ./python -c 'import pprint, warnings; pprint.pprint(warnings.filters)'
[('ignore', None, <class 'BytesWarning'>, None, 0),
 ('default', None, <class 'ResourceWarning'>, None, 0)]

-X dev adds a default filter *at the end*:

$ ./python -X dev -c 'import pprint, warnings; pprint.pprint(warnings.filters)'
[('ignore', None, <class 'BytesWarning'>, None, 0),
 ('default', None, <class 'ResourceWarning'>, None, 0),
 ('default', None, <class 'Warning'>, None, 0)]   <~~~ HERE

Note: you can combine -X dev with -W if you want ;-) (It works as expected.)

Victor
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to