(original) (raw)
Nick and Victor,
I'm still hoping to accept this PEP, but I don't have time to wrap my head around -Xdev ("devmode"?) which appears to be Victor's latest pet project. Should PEP 565 be changed to copy with devmode's behavior, or the other way around, or should they just ignore each other? It is not clear of me what the status of the mention in PEP 565 of -Xdev is -- normative or informational? I really don't want to have to learn how devmode works in order to be able to accept PEP 565 (or send it back for revision), so I am asking you two to let me know.
I'm still hoping to accept this PEP, but I don't have time to wrap my head around -Xdev ("devmode"?) which appears to be Victor's latest pet project. Should PEP 565 be changed to copy with devmode's behavior, or the other way around, or should they just ignore each other? It is not clear of me what the status of the mention in PEP 565 of -Xdev is -- normative or informational? I really don't want to have to learn how devmode works in order to be able to accept PEP 565 (or send it back for revision), so I am asking you two to let me know.
On Wed, Dec 6, 2017 at 1:42 AM, Victor Stinner <victor.stinner@gmail.com> wrote:
Let's discuss -Xdev implementation issue at https://bugs.python.org/issue32230 In short, -Xdev must add its warning at the end to respect BytesWarning, whereas it's not possible with -W option :-(VictorLe 6 déc. 2017 09:15, "Nick Coghlan" <ncoghlan@gmail.com> a écrit :On 6 December 2017 at 14:50, Nick Coghlan <ncoghlan@gmail.com> wrote:Having rebased the PEP 565 patch atop the "-X dev" changes, I think
\> On 6 December 2017 at 14:34, Nick Coghlan <ncoghlan@gmail.com> wrote:
\>> That said, I go agree we could offer easier to use APIs to app
\>> developers that just want to hide warnings from their users, so I've
\>> filed https://bugs.python.org/issue32229 to propose a straightforward
\>> "warnings.hide\_warnings()" API that encapsulates things like checking
\>> for a non-empty sys.warnoptions list.
\>
\> I've updated the "Limitations" section of the PEP to mention that
\> separate proposal:
\> https://github.com/python/peps/commit/6e93c8d2e6ad698834578d 4077b92a8fc84a70f5
that if we don't change some of the details of how \`-X dev\` is
implemented, \`warnings.hide\_warnings\` (or a comparable convenience
API) is going to be a requirement to help app developers effectively
manage their default warnings settings in 3.7+.
The problem is that devmode doesn't currently behave the same way
\`-Wd\` does when it comes to sys.warnoptions:
$ ./python -Wd -c "import sys; print(sys.warnoptions);
print(sys.flags.dev\_mode)"
\['d'\]
False
$ ./python -X dev -c "import sys; print(sys.warnoptions);
print(sys.flags.dev\_mode)"
\[\]
True
As currently implemented, the warnings module actually checks
\`sys.flags.dev\_mode\` directly during startup (or \`sys.\_xoptions\` in
the case of the pure Python fallback), and populates the warnings
filter differently depending on what it finds:
$ ./python -c "import warnings; print('\\n'.join(map(str,
warnings.filters)))"
('default', None, , '\_\_main\_\_', 0)
('ignore', None, , None, 0)
('ignore', None, , None, 0)
('ignore', None, , None, 0)
('ignore', None, , None, 0)
('ignore', None, , None, 0)$ ./python -X dev -c "import warnings; print('\\n'.join(map(str,
warnings.filters)))"
('ignore', None, , None, 0)
('default', None, , None, 0)
('default', None, , None, 0)$ ./python -Wd -c "import warnings; print('\\n'.join(map(str,
warnings.filters)))"
('default', None, , None, 0)('default', None, , '\_\_main\_\_', 0)
('ignore', None, , None, 0)
('ignore', None, , None, 0)
('ignore', None, , None, 0)
('ignore', None, , None, 0)
('ignore', None, , None, 0)This means the app development snippet proposed in the PEP will no
longer do the right thing, since it will ignore the dev mode flag:
if not sys.warnoptions:
\# This still runs for \`-X dev\`
warnings.simplefilter("ignore")
My main suggested fix would be to adjust the way \`-X dev\` is
implemented to include \`sys.warnoptions.append('default')\` (and remove
the direct dev\_mode query from the warnings module code).
However, another possible way to go would be to make the correct
Python 3.7+-only snippet look like this:
import warnings
warnings.hide\_warnings()
And have the forward-compatible snippet look like this:
import warnings:
if hasattr(warnings, "hide\_warnings"):
\# Accounts for \`-W\`, \`-X dev\`, and any other implementation
specific settings
warnings.hide\_warnings()
else:
\# Only accounts for \`-W\`
import sys
if not sys.warnoptions:(We can also do both, of course)
warnings.simplefilter("ignore")
\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
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/ guido%40python.org
--
--Guido van Rossum (python.org/\~guido)