diff -r f256bd5b8418 Doc/howto/pyporting.rst --- a/Doc/howto/pyporting.rst Thu Sep 29 22:33:02 2016 +0200 +++ b/Doc/howto/pyporting.rst Tue Oct 04 17:06:55 2016 -0700 @@ -298,12 +298,12 @@ from __future__ import print_function from __future__ import unicode_literals -You can also run Python 2 with the ``-3`` flag to be warned about various +You can also run Python 2 with the ``-3`` flag (or by setting the environment +variable ``PYTHON3WARNINGS`` to a non empty string) to be warned about various compatibility issues your code triggers during execution. If you turn warnings into errors with ``-Werror`` then you can make sure that you don't accidentally miss a warning. - You can also use the Pylint_ project and its ``--py3k`` flag to lint your code to receive warnings when your code begins to deviate from Python 3 compatibility. This also prevents you from having to run Modernize_ or Futurize_ diff -r f256bd5b8418 Doc/using/cmdline.rst --- a/Doc/using/cmdline.rst Thu Sep 29 22:33:02 2016 +0200 +++ b/Doc/using/cmdline.rst Tue Oct 04 17:06:55 2016 -0700 @@ -405,6 +405,8 @@ :exc:`DeprecationWarning` for features that are removed or significantly changed in Python 3. + See also :envvar:`PYTHON3WARNINGS`. + .. versionadded:: 2.6 Options you shouldn't use @@ -612,6 +614,12 @@ separated string, it is equivalent to specifying :option:`-W` multiple times. +.. envvar:: PYTHON3WARNINGS + + If this is set to a non-empty string it is equivalent to specifying the + :option:`-3` option. + + .. versionadded:: 2.7.13 .. envvar:: PYTHONHTTPSVERIFY diff -r f256bd5b8418 Lib/test/test_warnings.py --- a/Lib/test/test_warnings.py Thu Sep 29 22:33:02 2016 +0200 +++ b/Lib/test/test_warnings.py Tue Oct 04 17:06:55 2016 -0700 @@ -835,6 +835,24 @@ "['ignore::UnicodeWarning', 'ignore::DeprecationWarning']") self.assertEqual(p.wait(), 0) + def test_python3_warnings(self): + newenv = os.environ.copy() + newenv["PYTHON3WARNINGS"] = "1" + p = subprocess.Popen([sys.executable, + "-c", "import sys; sys.stdout.write(str(sys.py3kwarning))"], + stdout=subprocess.PIPE, env=newenv) + self.assertEqual(p.communicate()[0], "True") + self.assertEqual(p.wait(), 0) + + def test_python3_warnings_inactive(self): + newenv = os.environ.copy() + newenv["PYTHON3WARNINGS"] = "" + p = subprocess.Popen([sys.executable, + "-c", "import sys; sys.stdout.write(str(sys.py3kwarning))"], + stdout=subprocess.PIPE, env=newenv) + self.assertEqual(p.communicate()[0], "False") + self.assertEqual(p.wait(), 0) + class CEnvironmentVariableTests(EnvironmentVariableTests): module = c_warnings diff -r f256bd5b8418 Misc/ACKS --- a/Misc/ACKS Thu Sep 29 22:33:02 2016 +0200 +++ b/Misc/ACKS Tue Oct 04 17:06:55 2016 -0700 @@ -1564,3 +1564,4 @@ Jelle Zijlstra Gennadiy Zlobin Peter Åstrand +Roy Williams diff -r f256bd5b8418 Misc/NEWS --- a/Misc/NEWS Thu Sep 29 22:33:02 2016 +0200 +++ b/Misc/NEWS Tue Oct 04 17:06:55 2016 -0700 @@ -39,6 +39,10 @@ - Issue #27514: Make having too many statically nested blocks a SyntaxError instead of SystemError. +- Issue #28288: Allow Python 3 warnings to be enabled by setting the environment + variable PYTHON3WARNINGS to a non-emtpy string. + + Library ------- @@ -12092,4 +12096,3 @@ ---- **(For information about older versions, consult the HISTORY file.)** - diff -r f256bd5b8418 Modules/main.c --- a/Modules/main.c Thu Sep 29 22:33:02 2016 +0200 +++ b/Modules/main.c Tue Oct 04 17:06:55 2016 -0700 @@ -328,8 +328,6 @@ case '3': Py_Py3kWarningFlag++; - if (!Py_DivisionWarningFlag) - Py_DivisionWarningFlag = 1; break; case 'Q': @@ -450,6 +448,12 @@ if (Py_Py3kWarningFlag && !Py_TabcheckFlag) /* -3 implies -t (but not -tt) */ Py_TabcheckFlag = 1; + if (!Py_Py3kWarningFlag && + (p = Py_GETENV("PYTHON3WARNINGS")) && *p != '\0') + Py_Py3kWarningFlag++; + + if (Py_Py3kWarningFlag && !Py_DivisionWarningFlag) + Py_DivisionWarningFlag = 1; if (!Py_InspectFlag && (p = Py_GETENV("PYTHONINSPECT")) && *p != '\0') @@ -701,4 +705,3 @@ #ifdef __cplusplus } #endif -