Skip to content

Commit 6fc3be0

Browse files
committed
doc: Update open() default encoding docs for Python 3.15
Fixes #148603
1 parent 6009309 commit 6fc3be0

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

Doc/library/functions.rst

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ are always available. They are listed here in alphabetical order.
644644
If the given source is a string, then leading and trailing spaces and tabs
645645
are stripped.
646646

647-
See :func:`ast.literal_eval` for a function that can safely evaluate strings
647+
See :func:`ast.literal_eval` for a function to evaluate strings
648648
with expressions containing only literals.
649649

650650
.. audit-event:: exec code_object eval
@@ -1373,8 +1373,7 @@ are always available. They are listed here in alphabetical order.
13731373
already exists), ``'x'`` for exclusive creation, and ``'a'`` for appending
13741374
(which on *some* Unix systems, means that *all* writes append to the end of
13751375
the file regardless of the current seek position). In text mode, if
1376-
*encoding* is not specified the encoding used is platform-dependent:
1377-
:func:`locale.getencoding` is called to get the current locale encoding.
1376+
*encoding* is not specified, UTF-8 is used.
13781377
(For reading and writing raw bytes use binary mode and leave
13791378
*encoding* unspecified.) The available modes are:
13801379

@@ -1404,7 +1403,7 @@ are always available. They are listed here in alphabetical order.
14041403
argument) return contents as :class:`bytes` objects without any decoding. In
14051404
text mode (the default, or when ``'t'`` is included in the *mode* argument),
14061405
the contents of the file are returned as :class:`str`, the bytes having been
1407-
first decoded using a platform-dependent encoding or using the specified
1406+
first decoded using UTF-8 or using the specified
14081407
*encoding* if given.
14091408

14101409
.. note::
@@ -1433,9 +1432,8 @@ are always available. They are listed here in alphabetical order.
14331432
described above for binary files.
14341433

14351434
*encoding* is the name of the encoding used to decode or encode the file.
1436-
This should only be used in text mode. The default encoding is platform
1437-
dependent (whatever :func:`locale.getencoding` returns), but any
1438-
:term:`text encoding` supported by Python can be used.
1435+
This should only be used in text mode. The default encoding is UTF-8,
1436+
but any :term:`text encoding` supported by Python can be used.
14391437
See the :mod:`codecs` module for the list of supported encodings.
14401438

14411439
*errors* is an optional string that specifies how encoding and decoding
@@ -1549,6 +1547,9 @@ are always available. They are listed here in alphabetical order.
15491547
* On Windows, opening a console buffer may return a subclass of
15501548
:class:`io.RawIOBase` other than :class:`io.FileIO`.
15511549

1550+
.. versionchanged:: 3.15
1551+
The default encoding is now UTF-8, rather than locale-dependent.
1552+
15521553
.. versionchanged:: 3.11
15531554
The ``'U'`` mode has been removed.
15541555

@@ -1754,7 +1755,7 @@ are always available. They are listed here in alphabetical order.
17541755
self.age = age
17551756

17561757
def __repr__(self):
1757-
return f"Person('{self.name}', {self.age})"
1758+
return f"Person({self.name!r}, {self.age!r})"
17581759

17591760

17601761
.. function:: reversed(object, /)

0 commit comments

Comments
 (0)