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

Skip to content

Commit 742dfd6

Browse files
committed
Get rid of builtin_open() entirely (the C code and docstring, not the
builtin function); Guido pointed out that it could be just another name in the __builtin__ dict for the file constructor now.
1 parent 4b7625e commit 742dfd6

2 files changed

Lines changed: 5 additions & 22 deletions

File tree

Objects/fileobject.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,7 +1359,6 @@ file_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
13591359
return f;
13601360
}
13611361

1362-
/* XXX Keep this in synch with open_doc in bltinmodule.c. */
13631362
static char file_doc[] =
13641363
"file(name[, mode[, buffering]]) -> file object\n"
13651364
"\n"
@@ -1369,7 +1368,8 @@ static char file_doc[] =
13691368
"opened for writing. Add a 'b' to the mode for binary files.\n"
13701369
"Add a '+' to the mode to allow simultaneous reading and writing.\n"
13711370
"If the buffering argument is given, 0 means unbuffered, 1 means line\n"
1372-
"buffered, and larger numbers specify the buffer size.";
1371+
"buffered, and larger numbers specify the buffer size.\n"
1372+
"Note: open() is an alias for file().\n";
13731373

13741374
PyTypeObject PyFile_Type = {
13751375
PyObject_HEAD_INIT(&PyType_Type)

Python/bltinmodule.c

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,25 +1189,6 @@ static char oct_doc[] =
11891189
Return the octal representation of an integer or long integer.";
11901190

11911191

1192-
static PyObject *
1193-
builtin_open(PyObject *self, PyObject *args)
1194-
{
1195-
return PyFile_Type.tp_new(&PyFile_Type, args, NULL);
1196-
}
1197-
1198-
/* XXX Keep this in synch with file_doc in fileobject.c. */
1199-
static char open_doc[] =
1200-
"open(name[, mode[, buffering]]) -> file object\n"
1201-
"\n"
1202-
"Open a file. The mode can be 'r', 'w' or 'a' for reading (default),\n"
1203-
"writing or appending. The file will be created if it doesn't exist\n"
1204-
"when opened for writing or appending; it will be truncated when\n"
1205-
"opened for writing. Add a 'b' to the mode for binary files.\n"
1206-
"Add a '+' to the mode to allow simultaneous reading and writing.\n"
1207-
"If the buffering argument is given, 0 means unbuffered, 1 means line\n"
1208-
"buffered, and larger numbers specify the buffer size.";
1209-
1210-
12111192
static PyObject *
12121193
builtin_ord(PyObject *self, PyObject* obj)
12131194
{
@@ -1802,7 +1783,6 @@ static PyMethodDef builtin_methods[] = {
18021783
{"max", builtin_max, METH_VARARGS, max_doc},
18031784
{"min", builtin_min, METH_VARARGS, min_doc},
18041785
{"oct", builtin_oct, METH_O, oct_doc},
1805-
{"open", builtin_open, METH_VARARGS, open_doc},
18061786
{"ord", builtin_ord, METH_O, ord_doc},
18071787
{"pow", builtin_pow, METH_VARARGS, pow_doc},
18081788
{"range", builtin_range, METH_VARARGS, range_doc},
@@ -1861,6 +1841,9 @@ _PyBuiltin_Init(void)
18611841
SETBUILTIN("super", &PySuper_Type);
18621842
SETBUILTIN("tuple", &PyTuple_Type);
18631843
SETBUILTIN("type", &PyType_Type);
1844+
1845+
/* Note that open() is just an alias of file(). */
1846+
SETBUILTIN("open", &PyFile_Type);
18641847
SETBUILTIN("file", &PyFile_Type);
18651848
#ifdef Py_USING_UNICODE
18661849
SETBUILTIN("unicode", &PyUnicode_Type);

0 commit comments

Comments
 (0)