@@ -82,51 +82,58 @@ def open(file, mode="r", buffering=-1, encoding=None, errors=None,
8282 wrapped. (If a file descriptor is given, it is closed when the
8383 returned I/O object is closed, unless closefd is set to False.)
8484
85- mode is an optional string that specifies the mode in which the file is
86- opened. It defaults to 'r' which means open for reading in text mode. Other
87- common values are 'w' for writing (truncating the file if it already
88- exists), 'x' for exclusive creation of a new file, and 'a' for appending
89- (which on some Unix systems, means that all writes append to the end of the
90- file regardless of the current seek position). In text mode, if encoding is
91- not specified the encoding used is platform dependent. (For reading and
92- writing raw bytes use binary mode and leave encoding unspecified.) The
93- available modes are:
94-
95- ========= ===============================================================
85+ mode is an optional string that specifies the mode in which the file
86+ is opened. It defaults to 'r' which means open for reading in text
87+ mode. Other common values are 'w' for writing (truncating the file if
88+ it already exists), 'x' for exclusive creation of a new file, and
89+ 'a' for appending (which on some Unix systems, means that all writes
90+ append to the end of the file regardless of the current seek position).
91+ In text mode, if encoding is not specified the encoding used is platform
92+ dependent. (For reading and writing raw bytes use binary mode and leave
93+ encoding unspecified.) The available modes are:
94+
95+ ========= ==========================================================
9696 Character Meaning
97- --------- ---------------------------------------------------------------
97+ --------- ----------------------------------------------------------
9898 'r' open for reading (default)
9999 'w' open for writing, truncating the file first
100100 'x' create a new file and open it for writing
101- 'a' open for writing, appending to the end of the file if it exists
101+ 'a' open for writing, appending to the end of the file if it
102+ exists
102103 'b' binary mode
103104 't' text mode (default)
104105 '+' open a disk file for updating (reading and writing)
105- ========= ===============================================================
106+ ========= ==========================================================
106107
107108 The default mode is 'rt' (open for reading text). For binary random
108109 access, the mode 'w+b' opens and truncates the file to 0 bytes, while
109110 'r+b' opens the file without truncation. The 'x' mode implies 'w' and
110111 raises an `FileExistsError` if the file already exists.
111112
112113 Python distinguishes between files opened in binary and text modes,
113- even when the underlying operating system doesn't. Files opened in
114+ even when the underlying operating system doesn't. Files opened in
114115 binary mode (appending 'b' to the mode argument) return contents as
115- bytes objects without any decoding. In text mode (the default, or when
116+ bytes objects without any decoding. In text mode (the default, or when
116117 't' is appended to the mode argument), the contents of the file are
117118 returned as strings, the bytes having been first decoded using a
118119 platform-dependent encoding or using the specified encoding if given.
119120
120121 buffering is an optional integer used to set the buffering policy.
121- Pass 0 to switch buffering off (only allowed in binary mode), 1 to select
122- line buffering (only usable in text mode), and an integer > 1 to indicate
123- the size of a fixed-size chunk buffer. When no buffering argument is
124- given, the default buffering policy works as follows:
122+ Pass 0 to switch buffering off (only allowed in binary mode), 1 to
123+ select line buffering (only usable in text mode), and an integer > 1 to
124+ indicate the size of a fixed-size chunk buffer. When no buffering
125+ argument is given, the default buffering policy works as follows:
125126
126127 * Binary files are buffered in fixed-size chunks; the size of the buffer
128+ <<<<<<< HEAD
127129 is chosen using a heuristic trying to determine the underlying device's
128130 "block size" and falling back on `io.DEFAULT_BUFFER_SIZE`.
129131 On many systems, the buffer will typically be 4096 or 8192 bytes long.
132+ =======
133+ is max(min(blocksize, 8 MiB), DEFAULT_BUFFER_SIZE) when the device
134+ block size is available.
135+ On most systems, the buffer will typically be 128 kilobytes long.
136+ >>>>>>> 36137e46a8c ([3.14] gh-150285: Fix too long docstrings in the io module (GH-150287) (GH-150458))
130137
131138 * "Interactive" text files (files for which isatty() returns True)
132139 use line buffering. Other text files use the policy described above
@@ -146,8 +153,8 @@ def open(file, mode="r", buffering=-1, encoding=None, errors=None,
146153 encoding error strings.
147154
148155 newline is a string controlling how universal newlines works (it only
149- applies to text mode). It can be None, '', '\n', '\r', and '\r\n'. It works
150- as follows:
156+ applies to text mode). It can be None, '', '\n', '\r', and '\r\n'. It
157+ works as follows:
151158
152159 * On input, if newline is None, universal newlines mode is
153160 enabled. Lines in the input can end in '\n', '\r', or '\r\n', and
@@ -163,17 +170,17 @@ def open(file, mode="r", buffering=-1, encoding=None, errors=None,
163170 other legal values, any '\n' characters written are translated to
164171 the given string.
165172
166- closedfd is a bool. If closefd is False, the underlying file descriptor will
167- be kept open when the file is closed. This does not work when a file name is
168- given and must be True in that case.
173+ closedfd is a bool. If closefd is False, the underlying file descriptor
174+ will be kept open when the file is closed. This does not work when
175+ a file name is given and must be True in that case.
169176
170177 The newly created file is non-inheritable.
171178
172179 A custom opener can be used by passing a callable as *opener*. The
173- underlying file descriptor for the file object is then obtained by calling
174- *opener* with (*file*, *flags*). *opener* must return an open file
175- descriptor (passing os.open as *opener* results in functionality similar to
176- passing None).
180+ underlying file descriptor for the file object is then obtained by
181+ calling *opener* with (*file*, *flags*). *opener* must return an open
182+ file descriptor (passing os.open as *opener* results in functionality
183+ similar to passing None).
177184
178185 open() returns a file object whose type depends on the mode, and
179186 through which the standard file operations such as reading and writing
@@ -357,10 +364,12 @@ def seek(self, pos, whence=0):
357364 interpreted relative to the position indicated by whence. Values
358365 for whence are ints:
359366
360- * 0 -- start of stream (the default); offset should be zero or positive
367+ * 0 -- start of stream (the default); offset should be zero or
368+ positive
361369 * 1 -- current stream position; offset may be negative
362370 * 2 -- end of stream; offset is usually negative
363- Some operating systems / file systems could provide additional values.
371+ Some operating systems / file systems could provide additional
372+ values.
364373
365374 Return an int indicating the new absolute position.
366375 """
@@ -373,8 +382,8 @@ def tell(self):
373382 def truncate (self , pos = None ):
374383 """Truncate file to size bytes.
375384
376- Size defaults to the current IO position as reported by tell(). Return
377- the new size.
385+ Size defaults to the current IO position as reported by tell().
386+ Return the new size.
378387 """
379388 self ._unsupported ("truncate" )
380389
@@ -498,7 +507,8 @@ def __exit__(self, *args):
498507 def fileno (self ):
499508 """Returns underlying file descriptor (an int) if one exists.
500509
501- An OSError is raised if the IO object does not use a file descriptor.
510+ An OSError is raised if the IO object does not use a file
511+ descriptor.
502512 """
503513 self ._unsupported ("fileno" )
504514
@@ -1482,17 +1492,22 @@ class FileIO(RawIOBase):
14821492 _closefd = True
14831493
14841494 def __init__ (self , file , mode = 'r' , closefd = True , opener = None ):
1485- """Open a file. The mode can be 'r' (default), 'w', 'x' or 'a' for reading,
1486- writing, exclusive creation or appending. The file will be created if it
1487- doesn't exist when opened for writing or appending; it will be truncated
1488- when opened for writing. A FileExistsError will be raised if it already
1489- exists when opened for creating. Opening a file for creating implies
1490- writing so this mode behaves in a similar way to 'w'. Add a '+' to the mode
1491- to allow simultaneous reading and writing. A custom opener can be used by
1492- passing a callable as *opener*. The underlying file descriptor for the file
1493- object is then obtained by calling opener with (*name*, *flags*).
1494- *opener* must return an open file descriptor (passing os.open as *opener*
1495- results in functionality similar to passing None).
1495+ """Open a file.
1496+
1497+ The mode can be 'r' (default), 'w', 'x' or 'a' for reading,
1498+ writing, exclusive creation or appending. The file will be created
1499+ if it doesn't exist when opened for writing or appending; it will be
1500+ truncated when opened for writing. A FileExistsError will be raised
1501+ if it already exists when opened for creating. Opening a file for
1502+ creating implies writing so this mode behaves in a similar way to
1503+ 'w'. Add a '+' to the mode to allow simultaneous reading and
1504+ writing.
1505+
1506+ A custom opener can be used by passing a callable as *opener*.
1507+ The underlying file descriptor for the file object is then obtained
1508+ by calling opener with (*name*, *flags*). *opener* must return
1509+ an open file descriptor (passing os.open as *opener* results in
1510+ functionality similar to passing None).
14961511 """
14971512 if self ._fd >= 0 :
14981513 # Have to close the existing file first.
@@ -1702,8 +1717,8 @@ def write(self, b):
17021717 """Write bytes b to file, return number written.
17031718
17041719 Only makes one system call, so not all of the data may be written.
1705- The number of bytes actually written is returned. In non-blocking mode,
1706- returns None if the write would block.
1720+ The number of bytes actually written is returned. In non-blocking
1721+ mode, returns None if the write would block.
17071722 """
17081723 self ._checkClosed ()
17091724 self ._checkWritable ()
@@ -1715,11 +1730,12 @@ def write(self, b):
17151730 def seek (self , pos , whence = SEEK_SET ):
17161731 """Move to new file position.
17171732
1718- Argument offset is a byte count. Optional argument whence defaults to
1719- SEEK_SET or 0 (offset from start of file, offset should be >= 0); other values
1720- are SEEK_CUR or 1 (move relative to current position, positive or negative),
1721- and SEEK_END or 2 (move relative to end of file, usually negative, although
1722- many platforms allow seeking beyond the end of a file).
1733+ Argument offset is a byte count. Optional argument whence defaults
1734+ to SEEK_SET or 0 (offset from start of file, offset should be >= 0);
1735+ other values are SEEK_CUR or 1 (move relative to current position,
1736+ positive or negative), and SEEK_END or 2 (move relative to end of
1737+ file, usually negative, although many platforms allow seeking beyond
1738+ the end of a file).
17231739
17241740 Note that not all file objects are seekable.
17251741 """
@@ -1751,8 +1767,8 @@ def truncate(self, size=None):
17511767 def close (self ):
17521768 """Close the file.
17531769
1754- A closed file cannot be used for further I/O operations. close() may be
1755- called more than once without error.
1770+ A closed file cannot be used for further I/O operations.
1771+ close() may be called more than once without error.
17561772 """
17571773 if not self .closed :
17581774 try :
@@ -1831,8 +1847,8 @@ class TextIOBase(IOBase):
18311847 def read (self , size = - 1 ):
18321848 """Read at most size characters from stream, where size is an int.
18331849
1834- Read from underlying buffer until we have size characters or we hit EOF.
1835- If size is negative or omitted, read until EOF.
1850+ Read from underlying buffer until we have size characters or we hit
1851+ EOF. If size is negative or omitted, read until EOF.
18361852
18371853 Returns a string.
18381854 """
0 commit comments