Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3d2279f

Browse files
Issue #21859: Corrected FileIO docstrings.
1 parent 7e7a3db commit 3d2279f

1 file changed

Lines changed: 18 additions & 15 deletions

File tree

Modules/_io/fileio.c

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
267267
if (fd < 0) {
268268
if (!PyErr_Occurred()) {
269269
PyErr_SetString(PyExc_ValueError,
270-
"Negative filedescriptor");
270+
"negative file descriptor");
271271
return -1;
272272
}
273273
PyErr_Clear();
@@ -1094,10 +1094,10 @@ fileio_getstate(fileio *self)
10941094
PyDoc_STRVAR(fileio_doc,
10951095
"file(name: str[, mode: str][, opener: None]) -> file IO object\n"
10961096
"\n"
1097-
"Open a file. The mode can be 'r', 'w', 'x' or 'a' for reading (default),\n"
1097+
"Open a file. The mode can be 'r' (default), 'w', 'x' or 'a' for reading,\n"
10981098
"writing, exclusive creation or appending. The file will be created if it\n"
10991099
"doesn't exist when opened for writing or appending; it will be truncated\n"
1100-
"when opened for writing. A `FileExistsError` will be raised if it already\n"
1100+
"when opened for writing. A FileExistsError will be raised if it already\n"
11011101
"exists when opened for creating. Opening a file for creating implies\n"
11021102
"writing so this mode behaves in a similar way to 'w'.Add a '+' to the mode\n"
11031103
"to allow simultaneous reading and writing. A custom opener can be used by\n"
@@ -1123,22 +1123,22 @@ PyDoc_STRVAR(write_doc,
11231123
"write(b: bytes) -> int. Write bytes b to file, return number written.\n"
11241124
"\n"
11251125
"Only makes one system call, so not all of the data may be written.\n"
1126-
"The number of bytes actually written is returned.");
1126+
"The number of bytes actually written is returned. In non-blocking mode,\n"
1127+
"returns None if the write would block."
1128+
);
11271129

11281130
PyDoc_STRVAR(fileno_doc,
1129-
"fileno() -> int. \"file descriptor\".\n"
1130-
"\n"
1131-
"This is needed for lower-level file interfaces, such the fcntl module.");
1131+
"fileno() -> int. Return the underlying file descriptor (an integer).");
11321132

11331133
PyDoc_STRVAR(seek_doc,
11341134
"seek(offset: int[, whence: int]) -> int. Move to new file position and\n"
11351135
"return the file position.\n"
11361136
"\n"
11371137
"Argument offset is a byte count. Optional argument whence defaults to\n"
1138-
"0 (offset from start of file, offset should be >= 0); other values are 1\n"
1139-
"(move relative to current position, positive or negative), and 2 (move\n"
1140-
"relative to end of file, usually negative, although many platforms allow\n"
1141-
"seeking beyond the end of a file)."
1138+
"SEEK_SET or 0 (offset from start of file, offset should be >= 0); other values\n"
1139+
"are SEEK_CUR or 1 (move relative to current position, positive or negative),\n"
1140+
"and SEEK_END or 2 (move relative to end of file, usually negative, although\n"
1141+
"many platforms allow seeking beyond the end of a file).\n"
11421142
"\n"
11431143
"Note that not all file objects are seekable.");
11441144

@@ -1152,7 +1152,10 @@ PyDoc_STRVAR(truncate_doc,
11521152
#endif
11531153

11541154
PyDoc_STRVAR(tell_doc,
1155-
"tell() -> int. Current file position");
1155+
"tell() -> int. Current file position.\n"
1156+
"\n"
1157+
"Can raise OSError for non seekable files."
1158+
);
11561159

11571160
PyDoc_STRVAR(readinto_doc,
11581161
"readinto() -> Same as RawIOBase.readinto().");
@@ -1161,10 +1164,10 @@ PyDoc_STRVAR(close_doc,
11611164
"close() -> None. Close the file.\n"
11621165
"\n"
11631166
"A closed file cannot be used for further I/O operations. close() may be\n"
1164-
"called more than once without error. Changes the fileno to -1.");
1167+
"called more than once without error.");
11651168

11661169
PyDoc_STRVAR(isatty_doc,
1167-
"isatty() -> bool. True if the file is connected to a tty device.");
1170+
"isatty() -> bool. True if the file is connected to a TTY device.");
11681171

11691172
PyDoc_STRVAR(seekable_doc,
11701173
"seekable() -> bool. True if file supports random-access.");
@@ -1219,7 +1222,7 @@ get_mode(fileio *self, void *closure)
12191222
static PyGetSetDef fileio_getsetlist[] = {
12201223
{"closed", (getter)get_closed, NULL, "True if the file is closed"},
12211224
{"closefd", (getter)get_closefd, NULL,
1222-
"True if the file descriptor will be closed"},
1225+
"True if the file descriptor will be closed by close()."},
12231226
{"mode", (getter)get_mode, NULL, "String giving the file mode"},
12241227
{NULL},
12251228
};

0 commit comments

Comments
 (0)