Skip to content

Commit e288586

Browse files
committed
deprecate sys._enablelegacywindowsfsencoding()
1 parent 16c9415 commit e288586

3 files changed

Lines changed: 21 additions & 0 deletions

File tree

Doc/library/sys.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,11 +1644,21 @@ always available.
16441644
See also :func:`sys.getfilesystemencoding` and
16451645
:func:`sys.getfilesystemencodeerrors`.
16461646

1647+
.. note::
1648+
Changing the filesystem encoding after Python startup is dangerous.
1649+
This is because the old fsencoding or paths encoded by the old fsencoding
1650+
might be cached somewhere.
1651+
Use :envvar:`PYTHONLEGACYWINDOWSFSENCODING` instead of this API.
1652+
16471653
.. availability:: Windows.
16481654

16491655
.. versionadded:: 3.6
16501656
See :pep:`529` for more details.
16511657

1658+
.. deprecated-removed:: 3.13 3.16
1659+
Use :envvar:`PYTHONLEGACYWINDOWSFSENCODING` instead.
1660+
1661+
16521662
.. data:: stdin
16531663
stdout
16541664
stderr

Doc/whatsnew/3.13.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,10 @@ Deprecated
187187
practice.
188188
(Contributed by Victor Stinner in :gh:`106535`.)
189189

190+
* :mod:`sys`: :func:`sys._enablelegacywindowsfsencoding` function.
191+
Replace it with :envvar:`PYTHONLEGACYWINDOWSFSENCODING` environment variable.
192+
(Contributed by Inada Naoki in :gh:`73427`.)
193+
190194
* :mod:`typing`: Creating a :class:`typing.NamedTuple` class using keyword arguments to denote
191195
the fields (``NT = NamedTuple("NT", x=int, y=int)``) is deprecated, and will
192196
be disallowed in Python 3.15. Use the class-based syntax or the functional

Python/sysmodule.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1676,6 +1676,13 @@ static PyObject *
16761676
sys__enablelegacywindowsfsencoding_impl(PyObject *module)
16771677
/*[clinic end generated code: output=f5c3855b45e24fe9 input=2bfa931a20704492]*/
16781678
{
1679+
if (PyErr_WarnEx(
1680+
PyExc_DeprecationWarning,
1681+
"sys._enablelegacywindowsfsencoding() is deprecated and will be removed in Python 3.16. Use PYTHONLEGACYWINDOWSFSENCODING instead.",
1682+
1
1683+
)) {
1684+
return NULL;
1685+
}
16791686
if (_PyUnicode_EnableLegacyWindowsFSEncoding() < 0) {
16801687
return NULL;
16811688
}

0 commit comments

Comments
 (0)