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

Skip to content

Commit efc3a3a

Browse files
committed
SF bug [#463093] File methods need doc strings.
Now they don't.
1 parent c88425e commit efc3a3a

1 file changed

Lines changed: 94 additions & 14 deletions

File tree

Objects/fileobject.c

Lines changed: 94 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,23 +1281,103 @@ file_writelines(PyFileObject *f, PyObject *args)
12811281
return result;
12821282
}
12831283

1284+
static char readline_doc[] =
1285+
"readline([size]) -> next line from the file, as a string.\n"
1286+
"\n"
1287+
"Retain newline. A non-negative size argument limits the maximum\n"
1288+
"number of bytes to return (an incomplete line may be returned then).\n"
1289+
"Return an empty string at EOF.";
1290+
1291+
static char read_doc[] =
1292+
"read([size]) -> read at most size bytes, returned as a string.\n"
1293+
"\n"
1294+
"If the size argument is negative or omitted, read until EOF is reached.";
1295+
1296+
static char write_doc[] =
1297+
"write(str) -> None. Write string str to file.\n"
1298+
"\n"
1299+
"Note that due to buffering, flush() or close() may be needed before\n"
1300+
"the file on disk reflects the data written.";
1301+
1302+
static char fileno_doc[] =
1303+
"fileno() -> integer \"file descriptor\".\n"
1304+
"\n"
1305+
"This is needed for lower-level file interfaces, such os.read().";
1306+
1307+
static char seek_doc[] =
1308+
"seek(offset[, whence]) -> None. Move to new file position.\n"
1309+
"\n"
1310+
"Argument offset is a byte count. Optional argument whence defaults to\n"
1311+
"0 (offset from start of file, offset should be >= 0); other values are 1\n"
1312+
"(move relative to current position, positive or negative), and 2 (move\n"
1313+
"relative to end of file, usually negative, although many platforms allow\n"
1314+
"seeking beyond the end of a file).\n"
1315+
"\n"
1316+
"Note that not all file objects are seekable.";
1317+
1318+
#ifdef HAVE_FTRUNCATE
1319+
static char truncate_doc[] =
1320+
"truncate([size]) -> None. Truncate the file to at most size bytes.\n"
1321+
"\n"
1322+
"Size defaults to the current file position, as returned by tell().";
1323+
#endif
1324+
1325+
static char tell_doc[] =
1326+
"tell() -> current file position, an integer (may be a long integer).";
1327+
1328+
static char readinto_doc[] =
1329+
"readinto() -> Undocumented. Don't use this; it may go away.";
1330+
1331+
static char readlines_doc[] =
1332+
"readlines([size]) -> list of strings, each a line from the file.\n"
1333+
"\n"
1334+
"Call readline() repeatedly and return a list of the lines so read.\n"
1335+
"The optional size argument, if given, is an approximate bound on the\n"
1336+
"total number of bytes in the lines returned.";
1337+
1338+
static char xreadlines_doc[] =
1339+
"xreadlines() -> next line from the file, as a string.\n"
1340+
"\n"
1341+
"Equivalent to xreadlines.xreadlines(file). This is like readline(), but\n"
1342+
"often quicker, due to reading ahead internally.";
1343+
1344+
static char writelines_doc[] =
1345+
"writelines(list of strings) -> None. Write the strings to the file.\n"
1346+
"\n"
1347+
"Note that newlines are not added. This is equivalent to calling write()\n"
1348+
"for each string in the list.";
1349+
1350+
static char flush_doc[] =
1351+
"flush() -> None. Flush the internal I/O buffer.";
1352+
1353+
static char close_doc[] =
1354+
"close() -> None or (perhaps) an integer. Close the file.\n"
1355+
"\n"
1356+
"Sets data attribute .closed to true. A closed file cannot be used for\n"
1357+
"further I/O operations. close() may be called more than once without\n"
1358+
"error. Some kinds of file objects (for example, opened by popen())\n"
1359+
"may return an exit status upon closing.";
1360+
1361+
static char isatty_doc[] =
1362+
"isatty() -> true or false. True if the file is connected to a tty device.";
1363+
12841364
static PyMethodDef file_methods[] = {
1285-
{"readline", (PyCFunction)file_readline, METH_VARARGS},
1286-
{"read", (PyCFunction)file_read, METH_VARARGS},
1287-
{"write", (PyCFunction)file_write, METH_OLDARGS},
1288-
{"fileno", (PyCFunction)file_fileno, METH_NOARGS},
1289-
{"seek", (PyCFunction)file_seek, METH_VARARGS},
1365+
{"readline", (PyCFunction)file_readline, METH_VARARGS, readline_doc},
1366+
{"read", (PyCFunction)file_read, METH_VARARGS, read_doc},
1367+
{"write", (PyCFunction)file_write, METH_OLDARGS, write_doc},
1368+
{"fileno", (PyCFunction)file_fileno, METH_NOARGS, fileno_doc},
1369+
{"seek", (PyCFunction)file_seek, METH_VARARGS, seek_doc},
12901370
#ifdef HAVE_FTRUNCATE
1291-
{"truncate", (PyCFunction)file_truncate, METH_VARARGS},
1371+
{"truncate", (PyCFunction)file_truncate, METH_VARARGS, truncate_doc},
12921372
#endif
1293-
{"tell", (PyCFunction)file_tell, METH_NOARGS},
1294-
{"readinto", (PyCFunction)file_readinto, METH_OLDARGS},
1295-
{"readlines", (PyCFunction)file_readlines, METH_VARARGS},
1296-
{"xreadlines", (PyCFunction)file_xreadlines, METH_NOARGS},
1297-
{"writelines", (PyCFunction)file_writelines, METH_O},
1298-
{"flush", (PyCFunction)file_flush, METH_NOARGS},
1299-
{"close", (PyCFunction)file_close, METH_NOARGS},
1300-
{"isatty", (PyCFunction)file_isatty, METH_NOARGS},
1373+
{"tell", (PyCFunction)file_tell, METH_NOARGS, tell_doc},
1374+
{"readinto", (PyCFunction)file_readinto, METH_OLDARGS, readinto_doc},
1375+
{"readlines", (PyCFunction)file_readlines, METH_VARARGS, readlines_doc},
1376+
{"xreadlines", (PyCFunction)file_xreadlines, METH_NOARGS, xreadlines_doc},
1377+
{"writelines", (PyCFunction)file_writelines, METH_O, writelines_doc},
1378+
{"flush", (PyCFunction)file_flush, METH_NOARGS, flush_doc},
1379+
{"close", (PyCFunction)file_close, METH_NOARGS, close_doc},
1380+
{"isatty", (PyCFunction)file_isatty, METH_NOARGS, isatty_doc},
13011381
{NULL, NULL} /* sentinel */
13021382
};
13031383

0 commit comments

Comments
 (0)