func in cpython (original) (raw)

diff -r 8b79603699e4 Include/descrobject.h

--- a/Include/descrobject.h Wed Jul 18 00:02:56 2012 +0300

+++ b/Include/descrobject.h Thu Jul 19 19:39:57 2012 +0300

@@ -69,6 +69,7 @@

PyDescr_COMMON;

struct wrapperbase *d_base;

void *d_wrapped; /* This can be any function pointer */

} PyWrapperDescrObject;

#endif /* Py_LIMITED_API */

diff -r 8b79603699e4 Include/methodobject.h

--- a/Include/methodobject.h Wed Jul 18 00:02:56 2012 +0300

+++ b/Include/methodobject.h Thu Jul 19 19:39:57 2012 +0300

@@ -46,9 +46,12 @@

};

typedef struct PyMethodDef PyMethodDef;

-#define PyCFunction_New(ML, SELF) PyCFunction_NewEx((ML), (SELF), NULL)

-PyAPI_FUNC(PyObject *) PyCFunction_NewEx(PyMethodDef *, PyObject *,

- PyObject *);

+#define PyCFunction_New(ML, SELF) \

+#define PyCFunction_NewEx(ML, SELF, MODULE) \

+PyAPI_FUNC(PyObject *) PyCFunction_NewExEx(PyMethodDef *, PyObject *,

/* Flag passed to newmethodobject */

/* #define METH_OLDARGS 0x0000 -- unsupported now */

@@ -77,6 +80,7 @@

PyMethodDef *m_ml; /* Description of the C function to call */

PyObject *m_self; /* Passed as 'self' arg to the C func, can be NULL */

PyObject *m_module; /* The __module__ attribute, can be anything */

} PyCFunctionObject;

#endif

diff -r 8b79603699e4 Lib/functools.py

--- a/Lib/functools.py Wed Jul 18 00:02:56 2012 +0300

+++ b/Lib/functools.py Thu Jul 19 19:39:57 2012 +0300

@@ -9,10 +9,12 @@

# See C source code for _functools credits/copyright

__all__ = ['update_wrapper', 'wraps', 'WRAPPER_ASSIGNMENTS', 'WRAPPER_UPDATES',

- 'total_ordering', 'cmp_to_key', 'lru_cache', 'reduce', 'partial']

from _functools import partial, reduce

from collections import namedtuple

+from types import AllFunctionTypes

try:

from _thread import allocate_lock as Lock

except:

@@ -301,3 +303,13 @@

return update_wrapper(wrapper, user_function)

return decorating_function

+def unbind(f):

diff -r 8b79603699e4 Lib/inspect.py

--- a/Lib/inspect.py Wed Jul 18 00:02:56 2012 +0300

+++ b/Lib/inspect.py Thu Jul 19 19:39:57 2012 +0300

@@ -172,6 +172,27 @@

__kwdefaults__ dict of keyword only parameters with defaults"""

return isinstance(object, types.FunctionType)

+def isanyfunction(object):

+def isanyboundfunction(object):

+def isanyunboundfunction(object):

def isgeneratorfunction(object):

"""Return true if the object is a user-defined generator function.

diff -r 8b79603699e4 Lib/types.py

--- a/Lib/types.py Wed Jul 18 00:02:56 2012 +0300

+++ b/Lib/types.py Thu Jul 19 19:39:57 2012 +0300

@@ -28,6 +28,18 @@

ModuleType = type(sys)

+# XXX Note that the __func__ trick won't work anymore if we change the

+# semantics of classmethods' __func__ to not unbind when type(__self__)=type

+PyClassMethodDescriptorType = type(dict.fromkeys.__func__)

+MethodDescriptorType = type(list.append)

+WrapperDescriptorType = type(list.__add__)

+MethodWrapperType = type([].__add__)

+AllFunctionTypes = (PyClassMethodDescriptorType,

try:

raise TypeError

except TypeError:

diff -r 8b79603699e4 Objects/classobject.c

--- a/Objects/classobject.c Wed Jul 18 00:02:56 2012 +0300

+++ b/Objects/classobject.c Thu Jul 19 19:39:57 2012 +0300

@@ -244,8 +244,10 @@

else {

klassname = _PyObject_GetAttrId(klass, &PyId___name__);

if (klassname == NULL) {

- if (!PyErr_ExceptionMatches(PyExc_AttributeError))

return NULL;

PyErr_Clear();

}

else if (!PyUnicode_Check(klassname)) {

diff -r 8b79603699e4 Objects/descrobject.c

--- a/Objects/descrobject.c Wed Jul 18 00:02:56 2012 +0300

+++ b/Objects/descrobject.c Thu Jul 19 19:39:57 2012 +0300

@@ -115,7 +115,7 @@

((PyTypeObject *)type)->tp_name);

return NULL;

}

- return PyCFunction_New(descr->d_method, type);

}

static PyObject *

@@ -125,7 +125,7 @@

if (descr_check((PyDescrObject *)descr, obj, &res))

return res;

- return PyCFunction_New(descr->d_method, obj);

}

static PyObject *

@@ -239,7 +239,7 @@

return NULL;

}

- func = PyCFunction_New(descr->d_method, self);

if (func == NULL)

return NULL;

args = PyTuple_GetSlice(args, 1, argc);

@@ -292,7 +292,7 @@

return NULL;

}

- func = PyCFunction_New(descr->d_method, self);

if (func == NULL)

return NULL;

args = PyTuple_GetSlice(args, 1, argc);

@@ -398,6 +398,13 @@

return descr->d_qualname;

}

+static PyObject *

+method_get_func(PyMethodDescrObject *descr, void *closure)

+{

+}

static PyMemberDef descr_members[] = {

{"__objclass__", T_OBJECT, offsetof(PyDescrObject, d_type), READONLY},

{"__name__", T_OBJECT, offsetof(PyDescrObject, d_name), READONLY},

@@ -407,6 +414,7 @@

static PyGetSetDef method_getset[] = {

{"__doc__", (getter)method_get_doc},

{"__qualname__", (getter)descr_get_qualname},

{0}

};

@@ -452,9 +460,17 @@

return PyUnicode_FromString(descr->d_base->doc);

}

+static PyObject *

+wrapperdescr_get_func (PyWrapperDescrObject *descr, void *closure)

+{

+}

static PyGetSetDef wrapperdescr_getset[] = {

{"__doc__", (getter)wrapperdescr_get_doc},

{"__qualname__", (getter)descr_get_qualname},

{0}

};

@@ -1091,7 +1107,7 @@

};

static PyObject *

-wrapper_objclass(wrapperobject *wp)

+wrapper_objclass(wrapperobject *wp, void *closure)

{

PyObject *c = (PyObject *)PyDescr_TYPE(wp->descr);

@@ -1100,7 +1116,7 @@

}

static PyObject *

-wrapper_name(wrapperobject *wp)

+wrapper_name(wrapperobject *wp, void *closure)

{

const char *s = wp->descr->d_base->name;

@@ -1108,7 +1124,7 @@

}

static PyObject *

-wrapper_doc(wrapperobject *wp)

+wrapper_doc(wrapperobject *wp, void *closure)

{

const char *s = wp->descr->d_base->doc;

@@ -1122,16 +1138,24 @@

}

static PyObject *

-wrapper_qualname(wrapperobject *wp)

+wrapper_qualname(wrapperobject *wp, void *closure)

{

return descr_get_qualname((PyDescrObject *)wp->descr);

}

+static PyObject *

+wrapper_func(wrapperobject *wp, void *closure)

+{

+}

static PyGetSetDef wrapper_getsets[] = {

{"__objclass__", (getter)wrapper_objclass},

{"__name__", (getter)wrapper_name},

{"__qualname__", (getter)wrapper_qualname},

{"__doc__", (getter)wrapper_doc},

{0}

};

diff -r 8b79603699e4 Objects/methodobject.c

--- a/Objects/methodobject.c Wed Jul 18 00:02:56 2012 +0300

+++ b/Objects/methodobject.c Thu Jul 19 19:39:57 2012 +0300

@@ -14,7 +14,8 @@

#endif

PyObject *

-PyCFunction_NewEx(PyMethodDef *ml, PyObject *self, PyObject *module)

+PyCFunction_NewExEx(PyMethodDef *ml, PyObject *self, PyObject *module,

{

PyCFunctionObject *op;

op = free_list;

@@ -33,6 +34,8 @@

op->m_self = self;

Py_XINCREF(module);

op->m_module = module;

_PyObject_GC_TRACK(op);

return (PyObject *)op;

}

@@ -206,11 +209,30 @@

return self;

}

+static PyObject *

+meth_get__func__(PyCFunctionObject *m, void *closure)

+{

+}

static PyGetSetDef meth_getsets [] = {

{"__doc__", (getter)meth_get__doc__, NULL, NULL},

{"__name__", (getter)meth_get__name__, NULL, NULL},

{"__qualname__", (getter)meth_get__qualname__, NULL, NULL},

{"__self__", (getter)meth_get__self__, NULL, NULL},

{0}

};

@@ -347,16 +369,25 @@

numfree, sizeof(PyCFunction));

}

-/* PyCFunction_New() is now just a macro that calls PyCFunction_NewEx(),

- but it's part of the API so we need to keep a function around that

- existing C extensions can call.

+/* PyCFunction_New() and PyCFunction_NewEx() are now just macros that call

*/

#undef PyCFunction_New

+#undef PyCFunction_NewEx

PyAPI_FUNC(PyObject *) PyCFunction_New(PyMethodDef *, PyObject *);

+PyAPI_FUNC(PyObject *) PyCFunction_NewEx(

PyObject *

PyCFunction_New(PyMethodDef *ml, PyObject *self)

{

- return PyCFunction_NewEx(ml, self, NULL);

}

+PyObject *

+PyCFunction_NewEx(PyMethodDef *ml, PyObject *self, PyObject *module)

+{

+}