Skip to content

Commit b286d72

Browse files
Merge python#3
3: Add Py2x flag r=ltratt a=nanjekyejoannah This PR adds the Py2x flag: ``` Python 3.12.0a0 (heads/migration-dirty:5842fee697, May 23 2022, 00:25:04) [Clang 12.0.0 (clang-1200.0.32.29)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.flags sys.flags(debug=0, inspect=0, interactive=0, optimize=0, dont_write_bytecode=0, no_user_site=0, no_site=0, ignore_environment=0, verbose=0, bytes_warning=0, py2x_warning=1, quiet=0, hash_randomization=1, isolated=0, dev_mode=False, utf8_mode=0, warn_default_encoding=0) >>> ``` Co-authored-by: Joannah Nanjekye <[email protected]>
2 parents 5842fee + d6e20d1 commit b286d72

29 files changed

+95
-5
lines changed

Doc/c-api/exceptions.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,7 @@ the variables:
10831083
single: PyExc_SyntaxWarning
10841084
single: PyExc_UnicodeWarning
10851085
single: PyExc_UserWarning
1086+
single: PyExc_Py2xWarning
10861087
10871088
+------------------------------------------+---------------------------------+----------+
10881089
| C Name | Python Name | Notes |
@@ -1091,6 +1092,8 @@ the variables:
10911092
+------------------------------------------+---------------------------------+----------+
10921093
| :c:data:`PyExc_BytesWarning` | :exc:`BytesWarning` | |
10931094
+------------------------------------------+---------------------------------+----------+
1095+
| :c:data:`PyExc_Py2xWarning` | :exc:`Py2xWarning` | |
1096+
+------------------------------------------+---------------------------------+----------+
10941097
| :c:data:`PyExc_DeprecationWarning` | :exc:`DeprecationWarning` | |
10951098
+------------------------------------------+---------------------------------+----------+
10961099
| :c:data:`PyExc_FutureWarning` | :exc:`FutureWarning` | |

Doc/c-api/init.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ to 1 and ``-bb`` sets :c:data:`Py_BytesWarningFlag` to 2.
8989

9090
Set by the :option:`-b` option.
9191

92+
.. c:var:: int Py_Py2xWarningFlag
93+
94+
Issue a warning regarding 3.x compatibility.
95+
96+
Set by the :option:`-2` option.
97+
9298
.. c:var:: int Py_DebugFlag
9399
94100
Turn on parser debugging output (for expert only, depending on compilation

Doc/c-api/init_config.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,14 @@ PyConfig
617617
618618
Default: ``0``.
619619
620+
.. c:member:: int py2x_warning
621+
622+
If equals to ``1``, issue a warning for 3.x compatibility.
623+
624+
Incremented by the :option:`-2` command line option.
625+
626+
Default: ``0``.
627+
620628
.. c:member:: int warn_default_encoding
621629
622630
If non-zero, emit a :exc:`EncodingWarning` warning when :class:`io.TextIOWrapper`

Doc/library/exceptions.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,10 @@ The following exceptions are used as warning categories; see the
855855

856856
Base class for warnings related to :class:`bytes` and :class:`bytearray`.
857857

858+
.. exception:: Py2xWarning
859+
860+
Base class for warnings related to 3.x compatibility.
861+
858862

859863
.. exception:: ResourceWarning
860864

Doc/library/sys.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,7 @@ always available.
516516
:const:`ignore_environment` :option:`-E`
517517
:const:`verbose` :option:`-v`
518518
:const:`bytes_warning` :option:`-b`
519+
:const:`py2x_warning` :option:`-2`
519520
:const:`quiet` :option:`-q`
520521
:const:`hash_randomization` :option:`-R`
521522
:const:`dev_mode` :option:`-X dev <-X>` (:ref:`Python Development Mode <devmode>`)

Doc/library/warnings.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ The following warnings category classes are currently defined:
104104
| :exc:`BytesWarning` | Base category for warnings related to |
105105
| | :class:`bytes` and :class:`bytearray`. |
106106
+----------------------------------+-----------------------------------------------+
107+
| :exc:`Py2xWarning` | Base category for warnings related to |
108+
| | 3.x compatibility. |
109+
+----------------------------------+-----------------------------------------------+
107110
| :exc:`ResourceWarning` | Base category for warnings related to |
108111
| | resource usage (ignored by default). |
109112
+----------------------------------+-----------------------------------------------+

Include/cpython/initconfig.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ typedef struct PyConfig {
158158
PyWideStringList warnoptions;
159159
int site_import;
160160
int bytes_warning;
161+
int py2x_warning;
161162
int warn_default_encoding;
162163
int inspect;
163164
int interactive;

Include/cpython/pydebug.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ PyAPI_DATA(int) Py_NoUserSiteDirectory;
2020
PyAPI_DATA(int) Py_UnbufferedStdioFlag;
2121
PyAPI_DATA(int) Py_HashRandomizationFlag;
2222
PyAPI_DATA(int) Py_IsolatedFlag;
23+
PyAPI_DATA(int) Py_Py2xWarningFlag;
2324

2425
#ifdef MS_WINDOWS
2526
PyAPI_DATA(int) Py_LegacyWindowsFSEncodingFlag;

Include/pyerrors.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ PyAPI_DATA(PyObject *) PyExc_UnicodeWarning;
155155
PyAPI_DATA(PyObject *) PyExc_BytesWarning;
156156
PyAPI_DATA(PyObject *) PyExc_EncodingWarning;
157157
PyAPI_DATA(PyObject *) PyExc_ResourceWarning;
158+
PyAPI_DATA(PyObject *) PyExc_Py2xWarning;
158159

159160

160161
/* Convenience functions */

Lib/compileall.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,8 @@ def main():
375375
parser.add_argument('--hardlink-dupes', action='store_true',
376376
dest='hardlink_dupes',
377377
help='Hardlink duplicated pyc files')
378+
parser.add_argument('-2', dest='py2x', action='store_true',
379+
help='show warnings for 3.x compatibility')
378380

379381
args = parser.parse_args()
380382
compile_dests = args.compile_dest

0 commit comments

Comments
 (0)