On 9 November 2017 at 07:09, Simon Cross <hodgestar+python...@gmail.com> wrote: > On Wed, Nov 8, 2017 at 10:33 PM, Nick Coghlan <ncogh...@gmail.com> wrote: >> For interactive use, the principle ends up being "Code you write gives >> deprecation warnings, code you import doesn't" (which is the main >> aspect I care about, since it's the one that semi-regularly trips me >> up when I forget that DeprecationWarning is off by default). > > I with Antoine here. The idea that "code in __main__" is the set of code > someone > wrote really seems a lot like guessing (and not even very good guessing). > > If everyone follows the "keep __main__ small" then scripts won't automatically > display deprecation warnings by default and so the original problem of > "warnings > are easy to miss" remains.
That's an intended outcome - the goal is to have applications that are packaged in any way (installed Python package, importable packages with a __main__ submodule, zip archives with a __main__.py file) continue to silence deprecation warnings by default, as in those cases, the folks running them are *users* of those applications, rather than developers on them. > > Counter proposal -- why don't testing frameworks turn on warnings by default? > E.g. like pytest-warnings? That way people running tests will see warnings and > others won't unless they ask to see them. They do. The problem is that this only works for things that actually have test suites, which misses a lot of "Interactive Python is part of the user experience" use cases, like CPython's own REPL, and personal scripting on a platform like Linux or conda. However, between them, the following two guidelines should provide pretty good deprecation warning coverage for the world's Python code: 1. If it's in __main__, it will emit deprecation warnings at runtime 2. If it's not in __main__, it should have a test suite Thus the future answer to "I don't want deprecation warnings at runtime" becomes "Move it out of __main__ into an importable module, and give it a test suite". Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia _______________________________________________ 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