mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
SF patch 568629 by Oren Tirosh: types made callable.
These built-in functions are replaced by their (now callable) type: slice() buffer() and these types can also be called (but have no built-in named function named after them) classobj (type name used to be "class") code function instance instancemethod (type name used to be "instance method") The module "new" has been replaced with a small backward compatibility placeholder in Python. A large portion of the patch simply removes the new module from various platform-specific build recipes. The following binary Mac project files still have references to it: Mac/Build/PythonCore.mcp Mac/Build/PythonStandSmall.mcp Mac/Build/PythonStandalone.mcp [I've tweaked the code layout and the doc strings here and there, and added a comment to types.py about StringTypes vs. basestring. --Guido]
This commit is contained in:
parent
57454e57f8
commit
bea18ccde6
17 changed files with 287 additions and 130 deletions
|
@ -164,6 +164,30 @@ PySlice_GetIndicesEx(PySliceObject *r, int length,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
slice_new(PyTypeObject *type, PyObject *args, PyObject *kw)
|
||||
{
|
||||
PyObject *start, *stop, *step;
|
||||
|
||||
start = stop = step = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "O|OO:slice", &start, &stop, &step))
|
||||
return NULL;
|
||||
|
||||
/* This swapping of stop and start is to maintain similarity with
|
||||
range(). */
|
||||
if (stop == NULL) {
|
||||
stop = start;
|
||||
start = NULL;
|
||||
}
|
||||
return PySlice_New(start, stop, step);
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(slice_doc,
|
||||
"slice([start,] stop[, step])\n\
|
||||
\n\
|
||||
Create a slice object. This is used for extended slicing (e.g. a[0:10:2]).");
|
||||
|
||||
static void
|
||||
slice_dealloc(PySliceObject *r)
|
||||
{
|
||||
|
@ -240,7 +264,7 @@ PyTypeObject PySlice_Type = {
|
|||
0, /* tp_setattro */
|
||||
0, /* tp_as_buffer */
|
||||
Py_TPFLAGS_DEFAULT, /* tp_flags */
|
||||
0, /* tp_doc */
|
||||
slice_doc, /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
|
@ -252,4 +276,10 @@ PyTypeObject PySlice_Type = {
|
|||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
0, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
slice_new, /* tp_new */
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue